Carriage Return\Line feed in Java

后端 未结 6 935
滥情空心
滥情空心 2020-12-12 21:46

I have created a text file in Unix environment using Java code.

For writing the text file I am using java.io.FileWriter and BufferedWriter.

6条回答
  •  孤街浪徒
    2020-12-12 22:24

    bw.newLine(); cannot ensure compatibility with all systems.

    If you are sure it is going to be opened in windows, you can format it to windows newline.

    If you are already using native unix commands, try unix2dos and convert teh already generated file to windows format and then send the mail.

    If you are not using unix commands and prefer to do it in java, use ``bw.write("\r\n")` and if it does not complicate your program, have a method that finds out the operating system and writes the appropriate newline.

提交回复
热议问题