自己写的日志文件printTx
发布日期:2021-09-23 17:40:44 浏览次数:2 分类:技术文章

本文共 902 字,大约阅读时间需要 3 分钟。

public void printTxt(String log){    	try {	    	String filePath ="D:\\text.txt";	    	File file = new File(filePath);	    	//如果文件夹不存在则创建    	    	if  (!file.exists()  && !file .isDirectory())      	    	{       	    	    System.out.println("//不存在");  	    	    file.createNewFile();    	    	}	    	    		FileWriter fileWriter = new FileWriter(filePath, true); // true代表追加    		fileWriter.write(getCurrentDateString());    		fileWriter.write("\r\n");    		fileWriter.write(log);    		fileWriter.write("\r\n");    		fileWriter.write("\r\n");    		fileWriter.flush();    		fileWriter.close();					} catch (Exception e1) {			e1.printStackTrace();		}    }			private static SimpleDateFormat getDateParser(String pattern) {		return new SimpleDateFormat(pattern);	}		public static String getCurrentDateString() {		return getDateParse("yyyy-MM-dd HH:mm:ss").format(				new Date(System.currentTimeMillis()));	}

转载地址:https://blog.csdn.net/awj321000/article/details/51482341 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Java synchronized详解
下一篇:Memcached实现内存缓存

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月05日 15时53分29秒