public static void newFile(String filePathAndName, List list) {
try {
File myFilePath = new File(filePathAndName.toString());
// 如果该文件不存在,则创建
if (!myFilePath.exists()) {
myFilePath.createNewFile();
}
// FileWriter(myFilePath, true); 实现不覆盖追加到文件里
//FileWriter(myFilePath); 覆盖掉原来的内容
FileWriter resultFile = new FileWriter(myFilePath);
PrintWriter myFile = new PrintWriter(resultFile);
// 给文件里面写内容,原来的会覆盖掉
myFile.println(list);
resultFile.close();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
File myFilePath = new File(filePathAndName.toString());
// 如果该文件不存在,则创建
if (!myFilePath.exists()) {
myFilePath.createNewFile();
}
// FileWriter(myFilePath, true); 实现不覆盖追加到文件里
//FileWriter(myFilePath); 覆盖掉原来的内容
FileWriter resultFile = new FileWriter(myFilePath);
PrintWriter myFile = new PrintWriter(resultFile);
// 给文件里面写内容,原来的会覆盖掉
myFile.println(list);
resultFile.close();
} catch (Exception e) {
e.printStackTrace();
}
}