/**
* 向文本文件中寫入內(nèi)容或追加新內(nèi)容,如果append為true則直接追加新內(nèi)容,<br>
* 如果append為false則覆蓋原來的內(nèi)容<br>
*
* @param path
* @param content
* @param append
*/
public void writeFile(String path, String content, boolean append) {
File writefile;
try {
// 通過這個(gè)對象來判斷是否向文本文件中追加內(nèi)容
// boolean addStr = append;
writefile = new File(path);
// 如果文本文件不存在則創(chuàng)建它
if (writefile.exists() == false) {
writefile.createNewFile();
writefile = new File(path); // 重新實(shí)例化
}
FileOutputStream fw = new FileOutputStream(writefile);
System.out. fw.write(content.getBytes());
fw.flush();
fw.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
新聞熱點(diǎn)
疑難解答
圖片精選