I am creating a simple Notepad which reads text file,saves them and few common operation

My problem is that when it reads the file (a source code), it shows the whole code in one line , no line feed is followed. (new line is not detected, tab is detected

I am currently using BufferedReader with FileReader in JTextArea. enter image description hereAny suggestions ?

有帮助吗?

解决方案

My guess is that you expect BufferedReader.readLine() to return the line, including its ending EOL character sequence. That's not the case. readLine() returns the line without its ending line break. So you need to explicitely append a newline to the text area:

textArea.append(line);
textArea.append("\n");

其他提示

Please show us how are you using BufferedReader.

You can use bufferedReader.readLine() instead of bufferedReader.read(). Please note you should add new line manually in this case.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top