Symbian
Symbian OS Library

FAQ-0569 BufferedReader.readLine() method fails on my 5mx, is there a work around?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: java.io
Created: 01/31/2001 Modified: 07/19/2001
Number: FAQ-0569
Platform: ER5

Question:
The BufferedReader.readLine() method fails to detect the carriage return on my target hardware, although it worked OK on the emulator. Is there a work around?

Answer:
This is a known defect. A solution is to write your own readLine() method that detects the newline character '\n' .
For instance

public String readLine() throws java.io.IOException
{
StringBuffer s = new StringBuffer();
char c;
c = (char) in.read();
while (c != '\n')
{
if ((c == '\b') && (s.length() > 0))
{
s.setLength(s.length()-1);
}
else
{
s.append(c);
}
c = (char) in.read();
}
return(s.toString());
}


(posted on the Java Discussion Group by Maurice Castro; 16-11-1999).