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

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -