import java.io.*;
public class ReadFile{
public static void main(String []args)throws IOException{
/*
*Linux 系统分隔符为:/
*Window 系统分割符为:\\
*/
//写文件
File file2 = new File("C:\\write.txt");
if(!file2.exists()){file2.createNewFile();}//不存在则创建
//FileWriter 第二个参数声明为true,表示追加写,否则表示覆盖写
FileWriter writer = new FileWriter(file2,true);
BufferedWriter bwriter = new BufferedWriter(writer);
//三段论 File->FileWriter->BufferWriter
bwriter.write("Hello world!\n");
//写入一行,需要\n换行
}
}