I have to read an html as a text file and I have implemented two different methods as described on SO threads. I clean the html leaving just the body content to put it into DOM with document.write(string) with both methods, but it only works if I use Bufferedreader.readLine() (appending a stringBuilder in a loop). In fact, if I print the stringBuilder.toString() in the Logcat window I see that when BufferedReader.readLine() is used the stringBuilder is displayed on a single line in the Logcat window, while with InputStreamReader.read(charArray,0,(int)numBytes) it is displayed multi-line (I am using a real device). Maybe this can be related and suggest which is the issue. My question is : how have I to clean or process that char Array read by read(charArray,0,(int)numBytes) to be the same of the stringBuilder appended in the readLine() loop?
Share
The
BufferedReader.readLine()method reads till the end of the line and returns the value excluding the newline character. Hence when you append it to aStringBuffereverything gets appended to a single line. However, in the case ofInputStreamReader.read, the newline character is also included, causing the string to be displayed in multiple lines.To make the behavior similar, you will have to skip newline character while using
InputStreamReader.read.