开发中为了保存从东软传过来的XML数据 而创建一个日志文件

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();
                }
            }
            
        }
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值