android - Reading from text file, empty lines is skipped -
im writing app read text file located in assets folder.
lets text file this.
1.hello 2. 3.world 4.again
and using bufferedreader read line line (i want 3 first).
bufferedreader reader = new bufferedreader( new inputstreamreader(result.getcontext().getassets().open("file.txt"))); string text; (int x=0;x<3; x++) { text += reader.readline(); }
output becomes "helloworld". how like:
hello world
i though bufferedreader included empty lines textfile :s.
i tried manually create line break wanted if statement inside loop,
(int x=0;x<4; x++) { string s = reader.readline(); if(s.equals("")){ text+="\n"; }else { text += s; }
from java documentation bufferedreader#readline()
returns:
a string containing contents of line, not including line-termination characters, or null if end of stream has been reached
see bufferedreader.
you have add new line character manually in loop proposed checking empty string.
Comments
Post a Comment