//向文本文件中追加内容,如果append=true则默认追加,如果append=false会先清空文件再追加内容
public static boolean updateContent(String fileName,String content,boolean append){
boolean res = true;
File file = new File(fileName);
try {
if (!file.exists()) {
file.createNewFile();
}
FileWriter writer = new FileWriter(file,append);
if(append){
content = System.getProperty("line.separator")+content;
System.out.println(content);
}
writer.write(content);
writer.flush();
writer.close();
} catch (IOException ex) {
res = false;
ex.printStackTrace();
}
return res;
}
Android 向txt文本File中写入数据或清空数据
最新推荐文章于 2023-09-12 09:53:20 发布