PrintWriter to print on next line

前端 未结 3 1580
庸人自扰
庸人自扰 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条回答
  •  -上瘾入骨i
    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"));
    

提交回复
热议问题