package file; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; public class Demo6 {
public static void main(String[] args) throws IOException {
writeTest1();
} public static void writeTest1() throws IOException {
File file = new File("F:\\2.txt");
FileWriter fileWriter = new FileWriter(file);
// FileWriter fileWriter = new FileWriter(file,true);//如果追加,使用FileWriter(file,true)
//准备数据,写出
String data = "测试123数据";
fileWriter.write(data);
//关闭资源
// fileWriter.flush();
fileWriter.close(); }
}