Strings written to file do not preserve line breaks

后端 未结 5 1689
执笔经年
执笔经年 2020-11-28 13:27

I am trying to write a String(lengthy but wrapped), which is from JTextArea. When the string printed to console, formatting is same as it was in

5条回答
  •  盖世英雄少女心
    2020-11-28 13:59

    I just ran your program, and adding a carriage return (\r) before your newline (\n) did the trick for me.

    If you want to get a system independent line separator, one can be found in the system propery line.separator

    String separator = System.getProperty("line.separator");
    String string = "This is lengthy string that contains many words. So" + separator
                + "I am wrapping it.";
    

提交回复
热议问题