📄 logcommon.java
字号:
package librarymanagement.common;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 构建公共的写入日志文件类
* @author 虎兴龙
*
*/
public class LogCommon {
/**
* 获得PrintWrite对象
* @return
*/
public static PrintWriter getPrintWriteInstance(){
Calendar can = Calendar.getInstance();
SimpleDateFormat fileformate = new SimpleDateFormat("yyyy'年'MM'月'dd'日'");
String fileName = fileformate.format(can.getTime());
PrintWriter pw =null;
try {
pw = new PrintWriter(
new FileWriter("程序运行日志\\" + fileName + "日志.log", true), true);
} catch (IOException e2) {
e2.printStackTrace();
}
return pw;
}
/**
* 获得String类型的程序运行时刻
* @return
*/
public static String getCurrentTime(){
Calendar can = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy'年'MM'月'dd'日'HH:mm:ss");
String currentTime = formatter.format(can.getTime());
return currentTime;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -