How to write new line character to a file in Java

前端 未结 9 1563
执念已碎
执念已碎 2020-12-01 06:13

I have a string that contains new lines. I send this string to a function to write the String to a text file as:

    public static void writeResult(String wr         


        
9条回答
  •  离开以前
    2020-12-01 07:02

    Split the string in to string array and write using above method (I assume your text contains \n to get new line)

    String[] test = test.split("\n");
    

    and the inside a loop

    bufferedWriter.write(test[i]);
    bufferedWriter.newline();
    

提交回复
热议问题