Thursday, 15 September 2011

java - First characters being lost when reading from InputStream -



java - First characters being lost when reading from InputStream -

i have next code:

public class interface { public void exec(){ seek { _inputstream.read(); bufferedreader br = new bufferedreader( new inputstreamreader( _inputstream )); system.out.println( br.readline() ); } grab (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 run code though, printed out

" 4 n"

the first character has been lost. happening stream , can prevent it?

_inputstream.read();

consumes 1 character doesn't go bufferedreader. discarded character yourself. delete line , should fine.

java stream

No comments:

Post a Comment