如何高效将List数据按行写入文本文件,形成长尾?

2026-04-16 15:532阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计146个文字,预计阅读时间需要1分钟。

如何高效将List数据按行写入文本文件,形成长尾?

javaComUtil.javapublic class ComUtil { private static Logger logger=Logger.getLogger(ComUtil.class);

public static void writeToTxt(List lists, String fileNamePath) { String tempPath=null; Properties p=new Properties(); try { // Code logic here } catch (Exception e) { logger.error(Error writing to file, e); } }}

ComUtil.java

public class ComUtil { private static Logger logger = Logger.getLogger(ComUtil.class); public static void writeToTxt(List lists ,String fileNamePath) { String tempPath = null ; Properties p = new Properties(); try { InputStream in = ComUtil.class.getResourceAsStream(fileNamePath); p.load(in); in.close(); tempPath = p.getProperty("path"); if (tempPath.indexOf(".txt") < 0) { tempPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + System.currentTimeMillis() + ".txt"; }else{ tempPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + System.currentTimeMillis() + ".txt"; } for(Object list : lists){ String str =String.valueOf(list) + System.getProperty("line.separator") ; FileOutputStream fos = new FileOutputStream(tempPath,true); fos.write(str.getBytes()); fos.close(); } } catch (IOException e) { } } }

如何高效将List数据按行写入文本文件,形成长尾?

本文共计146个文字,预计阅读时间需要1分钟。

如何高效将List数据按行写入文本文件,形成长尾?

javaComUtil.javapublic class ComUtil { private static Logger logger=Logger.getLogger(ComUtil.class);

public static void writeToTxt(List lists, String fileNamePath) { String tempPath=null; Properties p=new Properties(); try { // Code logic here } catch (Exception e) { logger.error(Error writing to file, e); } }}

ComUtil.java

public class ComUtil { private static Logger logger = Logger.getLogger(ComUtil.class); public static void writeToTxt(List lists ,String fileNamePath) { String tempPath = null ; Properties p = new Properties(); try { InputStream in = ComUtil.class.getResourceAsStream(fileNamePath); p.load(in); in.close(); tempPath = p.getProperty("path"); if (tempPath.indexOf(".txt") < 0) { tempPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + System.currentTimeMillis() + ".txt"; }else{ tempPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + System.currentTimeMillis() + ".txt"; } for(Object list : lists){ String str =String.valueOf(list) + System.getProperty("line.separator") ; FileOutputStream fos = new FileOutputStream(tempPath,true); fos.write(str.getBytes()); fos.close(); } } catch (IOException e) { } } }

如何高效将List数据按行写入文本文件,形成长尾?