代码实现
public static int saveFile(String filePath, String content) {
File file = new File(filePath);
try {
file.createNewFile();
System.out.println("成功创建文件...");
FileWriter fw = new FileWriter(file);
fw.write(content); // 写入内容
fw.flush(); // write方法是写入缓存区,并没有写进file文件里面,要使用flush方法才写进去
fw.close(); // 关闭
} catch (IOException e) {
System.out.println("文件写入异常...");
e.printStackTrace();
}
return 1;
}