write newline into a file

后端 未结 9 1771
慢半拍i
慢半拍i 2020-12-05 05:28

considering the following function

private static void GetText(String nodeValue) throws IOException {

   if(!file3.exists()) {
       file3.createNewFile();         


        
相关标签:
9条回答
  • Solution:

    in WINDOWS you should write "\r\n" for a new line.

    0 讨论(0)
  • 2020-12-05 06:21

    the other answers should work. however I wanna mention

    from java doc:

    FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.

    reading your method codes, you are about to write String to the file, what you were doing is convert String to raw bytes, then write so I think using FileWriter is not a bad idea.

    And for the newline problem, Writer has method .write(String), which is convenient to use.

    0 讨论(0)
  • 2020-12-05 06:24

    just use \r\n for endline if you are using windows operating system.

    0 讨论(0)
提交回复
热议问题