JTextarea content writing into a file
Hi,I am having one problem while writing the content of JTextarea to a file.e.g if my textarea contains the following lines:
line1: A
line2: B
line3:\n
line4:\n
if I am writing using "BufferedWriter wr=new BufferedWriter(new FileWriter(file));
wr.write(textarea.getText());" some additional junk characters are added in to the file which can be seen if I open the file in notepad.
The second approach which I used was,if the textarea content I am splitting line by line with the readline() method and writing line by line into the file, such as "BufferedReader reader = new BufferedReader(new StringReader(
textArea.getText()));
out1 = new PrintWriter(file);
while ((l_stSingleLine = reader.readLine()) != null ) {
out1.println(l_stSingleLine);
out1.flush();
}
}"
One extra "\n" is added at last i.e after the write operation file contains five lines(Using the second approach the junk characters are not coming).Please help me in writing the file with exact content.
Re: JTextarea content writing into a file
Do you know that the notepad program treats the end of line and carriage return characters differently than the wordpad program. notepad will insert a small square when it doesn't understand the character n the file.
Look at the file with wordpad. How does it look there?
Or use the System.getProperty("line.separator") String to separate lines in the output file.
Re: JTextarea content writing into a file