//文件路径
String fileName = "G:\\SurfchnhorLog\\Desktop\\test\\log.txt";
File file = new File(fileName);
String path=fileName;
try { //如果文件不存在,则创建
if(fileName.endsWith("/") || fileName.endsWith("\\")){
}else{
path=file.getParent();
}
File f2=new File(path);
if (!(f2.exists())) {
f2.mkdirs();
} else {
}
//打开一个写文件器,第二个参数true表示以追加形式写文件,false表示覆盖
FileWriter fw = new FileWriter(fileName, true);
fw.write("222"+",");//System.getProperty("line.separator") 表示换行
fw.write("444"+System.getProperty("line.separator"));
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
java实现文件内容追加
最新推荐文章于 2024-08-02 03:57:22 发布