Solve the problem that filewriter writes text without newline

Time:2022-7-30

Filewriter writes text without wrapping

String str= “an opponent who can’t be modified \ R \ nwill bring out warmth forever behind \ R \ nalways wordy and always concerned \ R \ nit’s too guilty to know how to cherish”;

solve

Previously, I found that the written text did not wrap at all. What should I do? I changed it to \r\n wrap.

Precautions 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 will be automatically created

2. If the specified file exists, the write will be overwritten

3. If you do not want to overwrite writing, but want to append, then use another construction method of overload situation

public FileWriter(String fileName , boolean append); If the second parameter is true, it will be written additionally
*/
public class dwmo1 {
public static void main(String[] args) throws IOException {
FileWriter fw=new FileWriter(“file01.txt”,true);// create
fw.write(“java”);// write
fw.close();// shut
}
}

The above is my personal experience. I hope I can give you a reference, and I hope you can support developeppaer.

Recommended Today

JS generate guid method

JS generate guid method https://blog.csdn.net/Alive_tree/article/details/87942348 Globally unique identification(GUID) is an algorithm generatedBinaryCount Reg128 bitsNumber ofidentifier , GUID is mainly used in networks or systems with multiple nodes and computers. Ideally, any computational geometry computer cluster will not generate two identical guids, and the total number of guids is2^128In theory, it is difficult to make two […]