国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Java > 正文

將內(nèi)容寫到txt文檔里面并讀取及刪除的方法

2019-11-26 15:48:24
字體:
供稿:網(wǎng)友
1、將內(nèi)容寫到txt文檔里面
復(fù)制代碼 代碼如下:

public static void writeFile() {
String txtFileName = "emailRecord.txt";
String directoryPath = "";
try {
directoryPath = WebplusContext.getRealPath("/apps/schoolfellow/upload/smsRecord");
File directory = new File(directoryPath);
if (!directory.exists()) {
directory.mkdirs();
}
File txtFile = new File(directoryPath, txtFileName);
FileOutputStream out = new FileOutputStream(txtFile, true);
String line = System.getProperty("line.separator");
String smsContent = "將內(nèi)容寫到txt文件里面!" + line;
out.write(smsContent.toString().getBytes("GBK"));
out.close();
} catch (Exception ex) {
log.error("將結(jié)果寫入文件失敗!", ex);
}
}

2、讀取文件里面的內(nèi)容
復(fù)制代碼 代碼如下:

public void readerFile() {
String filePath = WebplusContext.getServletContext().getRealPath("/apps/schoolfellow/upload/emailRecord/emailRecord.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(filePath);
InputStreamReader reader = new InputStreamReader(fis, "GBK");
BufferedReader br = new BufferedReader(reader);
String info = "";
schoolfellows = new ArrayList<SchoolfellowDataViewWrap>();
while ((info = br.readLine()) != null) {
System.out.println(info);
}
br.close();
fis.close();
} catch (Exception ex) {
log.error("讀取數(shù)據(jù)失敗", ex);
} finally {
}
}

3、清除txt文件里面的內(nèi)容
復(fù)制代碼 代碼如下:

public void clearFileContent() {
String filePath = WebplusContext.getServletContext().getRealPath("/apps/schoolfellow/upload/emailRecord/emailRecord.txt");
try {
FileOutputStream out = new FileOutputStream(filePath,false);
out.write(new String("").getBytes());
out.close();
script = "alert('清空發(fā)送郵件日志成功!');";
} catch (Exception ex) {
script = "alert('清空文件的內(nèi)容失敗,因?yàn)闆]有發(fā)送郵件日志文件!');";
}
}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 榆社县| 兴山县| 班戈县| 乐东| 积石山| 西畴县| 德阳市| 阿拉善右旗| 承德县| 确山县| 台南市| 丰原市| 龙山县| 拉孜县| 陇南市| 英吉沙县| 台东市| 临洮县| 农安县| 东兰县| 治多县| 法库县| 星座| 盐池县| 寻乌县| 双峰县| 乌审旗| 新蔡县| 江北区| 吴川市| 胶南市| 临颍县| 黔西县| 石楼县| 吉首市| 司法| 确山县| 资兴市| 阿合奇县| 鄂州市| 福安市|