I am using BufferedReader object to read line from HTTP server through FileInputStream. readline() function returns a line skipping end of line character. But my requirement need to read full characters as it will be used to verify the signature. Signature verification fails if any character mismatch from the content. Please help me solve this problems
Asked
Active
Viewed 380 times
0
-
Do you need to break the text into separate lines as you read it? – Joni Jul 07 '20 at 15:20
1 Answers
0
Could you not just append "\n" onto the end of the string returned from readLine()?
You could also use the plain "read" method in the BufferedReader class like
BufferedReader in = new BufferedReader(new FileReader(file));
int ch;
while((ch = in.read()) != -1) {
//do processing with (char)ch
}
This will read every character, without stripping the \n

Swayne
- 16
- 1
-
-
hi Swayne, will there be any performance hit if we read char by char using read function instead of readLine function? – Tamil200 Jul 08 '20 at 05:10
-
Well it will take roughly the same time to read one character with .read() as it will to read a full line with readLine(), and so depending on the length of your lines is how much slower it will be – Swayne Jul 08 '20 at 23:10
-
I suggest reading more here: https://stackoverflow.com/questions/41324192/why-is-bufferedreader-read-much-slower-than-readline/41324983#:~:text=Reason%20two%3A%20In%20the%20class,at%20reading%20an%20entire%20file. And – Swayne Jul 08 '20 at 23:11