自己写的日志文件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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月05日 15时53分29秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
004_变量的声明以及获取
2019-04-27
005_变量的引用与赋值
2019-04-27
006_关于变量定义的状态
2019-04-27
007_shell中把变量重置为null
2019-04-27
008_shell创建只读量
2019-04-27
009_shell中从标准输入信息
2019-04-27
010_bash脚本的参数传递
2019-04-27
011_命令行参数的左移
2019-04-27
012_bash中的if判断条件
2019-04-27
013_bash中的加法
2019-04-27
014_bash中的for循环
2019-04-27
015_Arduino上实现一个简单的番茄时钟
2019-04-27
021_Excel的条件格式
2019-04-27
022_Excel空白值批量填充默认值
2019-04-27
023_emacs git-gutter+报错解决
2019-04-27
024_spacemacs支持org-pomodoro的声音提示
2019-04-27
025_everything搜索使用体验
2019-04-27
026_好用的windows小工具clover
2019-04-27
027-Mac触摸板实现窗口移动
2019-04-27
028_AUTOSAR RTE学习笔记-1
2019-04-27