PrintWriter to print on next line

前端 未结 3 1579
庸人自扰
庸人自扰 2020-12-10 18:18

I have the following code to print a string(from a ResultSet) to a text file:

PrintWriter writer = new PrintWriter(new FileOutputStream(file, false));
while(         


        
相关标签:
3条回答
  • 2020-12-10 18:50

    You can use PrintWriter#println() method instead.

    From API:

    Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

    Also this should work as well.

    writer.write(RS.getString(1)+ System.getProperty("line.separator"));
    
    0 讨论(0)
  • You should use println to print a newline character after each line:

    writer.println(RS.getString(1));
    
    0 讨论(0)
  • 2020-12-10 19:10

    Use, in the statement. For example:

    writer.print("1"+"<br/>");
    writer.print("2"+"<br/>");
    
    0 讨论(0)
提交回复
热议问题