write newline into a file

后端 未结 9 1775
慢半拍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条回答
  •  渐次进展
    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.

提交回复
热议问题