How to write multiple lines in a file when these multiple lines are taken as input from JTextarea?

I take several lines as input from JTextarea. If I write it in a file, I get that several lines are written to one line in the file

Examples:

In JTextArea:

I am a student 

Tool: variable.text = "I '\ n'am' \ n'a '\ n'student"; When I write the string s in the file, I get:

 I am a student 

But I want the file to contain the same things as me, as an input tool --->

 I am a student 

This is the file write code:

  BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(file), "UTF16")); int size=1; for(Tableclass variable:tablevector) { out.write(variable.Text); out.newLine(); size++; } out.close(); 
+4
source share
3 answers

Slightly improved version:

  try { PrintWriter fstream = new PrintWriter(new FileWriter("log.txt")); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for(String word : jTextAreaName.getText().split("\n")) { fstream.println(word); } fstream.flush(); 
+3
source

Use out.newLine ();

  BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(file), "UTF16")); int size=1; for(Tableclass variable:tablevector) { out.write(variable.Text); out.newLine(); size++; } out.close(); 
+2
source

find char in your string char (10) or char (13)

 int index = textarea.firstIndexOf(CHAR(10)); 
+1
source

Source: https://habr.com/ru/post/1411786/


All Articles