Solve the problem that FileWriter writes text without wrapping

  • 2021-11-02 00:46:51
  • OfStack

FileWriter Write text without wrapping

String str= "An opponent who can't be modified\ r\ n brings warmth and is always behind it\ r\ n always pays attention\ r\ n doesn't know how to cherish too much guilt";

Solve

Before using\ n, it was found that the written text did not wrap at all. What should I do? Change it to\ r\ n to wrap.

Considerations for Using FileWriter

package Preview


import java.io.FileWriter;
import java.io.IOException;
/*

When using FileWriter,

1. If the specified file does not exist, it is automatically created

2. If the specified file exists, the write to the

3. If you don't want an overwrite write, but you want an append, use another overloaded situation construction method


public FileWriter(String fileName , boolean append); No. 1 2 Parameters if yes true Value, the write to the 
*/
public class dwmo1 {
public static void main(String[] args) throws IOException {
FileWriter fw=new FileWriter( " file01.txt " ,true);// Chuang 
fw.write( " java " );// Write 
fw.close();// Guan 
}
}

Related articles: