zoukankan      html  css  js  c++  java
  • 输出内容到文件(日志输出)

    package writetotextfile;
    
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    
    public class Write {
    
        public static void main(String[] args) throws IOException {
            String filePath = "E:/writetext8/log.txt";
            String file = filePath.substring(0, filePath.lastIndexOf("/"));
            File logfile = new File(file);
            if (!logfile.exists()) {
                logfile.mkdirs();
            }
            File log = new File(filePath);
            if (!log.exists()) {
                log.createNewFile();
            }
            String content = "
    
    请求来源ip为:
    127.0.0.1
    请求时间为:
    "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss-SSS").format(new Date())+"
    请求参数为:
    666";
            writeByFileWrite(filePath,content);
        }
        public static void writeByFileWrite(String _sDestFile, String _sContent)
                throws IOException {
            FileWriter fw = null;
            try {
                fw = new FileWriter(_sDestFile,true);
                fw.write(_sContent);
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                if (fw != null) {
                    fw.close();
                    fw = null;
                }
            }
        }
    
    }
  • 相关阅读:
    wp8 入门到精通 测量代码执行时间
    过滤器——Filter
    hisui培训笔记
    监听器——servlet
    easyui导出excel表格和遇到的问题
    Java自定义注解
    Json
    Ajax
    探索Java中new一个对象时发生了什么
    SpringBoot常用注解
  • 原文地址:https://www.cnblogs.com/liqforstudy/p/5593321.html
Copyright © 2011-2022 走看看