当前位置 : 主页 > 编程语言 > c++ >

给定一个List,把List中数据,按行写入文本文件中

来源:互联网 收集:自由互联 发布时间:2021-06-30
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.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) {

		}  
      }
}
网友评论