package com.xiangshuai;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.omg.CORBA.PUBLIC_MEMBER;
/**
* * @author lqx 创建一个日志文件用来保存 某些信息
* 为了保存从东软传过来的XML数据 而创建一个日志文件
* 文件在 :E:\学习文档子目录压缩\工具技术2\创建一个日志文件用来保存 某些信息的代码\Demo.rar
* 我的网盘\我的笔记\学习文档子目录压缩\工具技术2\创建一个日志文件用来保存 某些信息的代码\Demo.rar
*/
public class PrintLog {
public static void main(String[] args) {
String xml="CCC6";
log(xml, new Date());
}
public static void log(String xml, Date date) {
PrintWriter printWriter = null;
FileWriter fW=null;
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
String formatStr =formatter.format(date);
System.out.println(formatStr);//2017-09-15 13:18:44:672
fW=new FileWriter(new File("E:/sqgdXmlLog.txt"),true);//输出流 ,true参数 写入E:/sqgdXmlLog.txt时每次在原有文件内容的基础上加
printWriter=new PrintWriter(fW); //PrintWriter 事fW的套流 就像BufferedInputStream一样
printWriter.println("申请归档时间 "+formatStr);
printWriter.println(xml);
printWriter.println("==========结束=================");
printWriter.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
if(printWriter!=null){
printWriter.close();
}
if(fW!=null){
try {
fW.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}