elog.java

来自「一个Mp3在线搜索器」· Java 代码 · 共 47 行

JAVA
47
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package biz.tbuy.huliqing.jloading;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;/** * * @author huliqing */public class Elog {    public Elog() {    }      public static void log(String message) {        try {            File logPath = new File("logs");            if (!logPath.exists()) {                logPath.mkdirs();            }            Date theDate = new Date();            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");            String fileName = "log" + sdf.format(theDate) + ".txt";            sdf.applyPattern("HH:mm:ss");            String nowTime = sdf.format(theDate);            File logFile = new File(logPath, fileName);            FileWriter fw = null;                    fw = new FileWriter(logFile, true);            fw.write("Log:[" + nowTime + "]");            fw.write(message + "\r\n");            fw.flush();            fw.close();        } catch (IOException ioe) {            //System.out.println("Elog:log:I/O Error");        }     }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?