I have the following code:
public class Interface {
public void exec(){
try {
_inputStream.read();
BufferedReader br = new BufferedReader( new InputStreamReader( _inputStream ));
System.out.println( br.readLine() );
} catch (IOException e) {
}
}
public void setInputStream( InputStream inputStream ){
_inputStream = inputStream;
}
private InputStream _inputStream;
}
public class Run {
public static void main(String[] args) {
Interface ui = new Interface();
ui.setInputStream( new ByteArrayInputStream( "2 4 N".getBytes( Charset.defaultCharset() ) ) );
ui.exec();
}
}
Whenever I run this code though, all I get printed out is
" 4 N"
The first character has been lost. What is happening to my stream and what can I do to prevent it?
consumes one character that doesn’t go to the
BufferedReader. You discarded that character yourself. Just delete that line and you should be fine.