gpt4 book ai didi

将内容写到txt文档里面并读取及删除的方法

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 24 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章将内容写到txt文档里面并读取及删除的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

1、将内容写到txt文档里面  。

复制代码代码如下

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 = "将内容写到txt文件里面!" + line;  out.write(smsContent.toString().getBytes("GBK"));  out.close();  } catch (Exception ex) {  log.error("将结果写入文件失败!", ex);  }  }  。

2、读取文件里面的内容  。

复制代码代码如下

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("读取数据失败", ex);  } finally {  }  }  。

3、清除txt文件里面的内容  。

复制代码代码如下

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('清空发送邮件日志成功!');";  } catch (Exception ex) {  script = "alert('清空文件的内容失败,因为没有发送邮件日志文件!');";  }  }  。

 

最后此篇关于将内容写到txt文档里面并读取及删除的方法的文章就讲到这里了,如果你想了解更多关于将内容写到txt文档里面并读取及删除的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com