TestPrintStream_3(打印流测试)

来源:互联网 发布:药物靶点数据库 编辑:程序博客网 时间:2024/05/16 14:43

/**
*Title:TestPrintStream_3(打印流测试)
*description:用于记录电脑用户的操作,并生成日志文档。
*@Copyright:
*@Company:
*@autor:firefly
*@version:1.0
*@time:2012.9.26
*/

import java.io.*;
import java.util.*;//运用这个包里面的Date(),可以显示出当前日期,精确到毫秒!

public class TestPrintStream_3 {
 public static void main(String[] args) {
  String s = null;
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  try{
   FileWriter fw = new FileWriter("G:\\java学习宝典\\TestPrintStream_3.log", true);
   //这里的true有自动刷新的功能,并把写上内容自动接在上一次写的内容后面。
   PrintWriter log = new PrintWriter(fw);
   while((s = br.readLine()) != null){
    if(s.equalsIgnoreCase("exit"))//字符串中的方法忽略大小写。
     break;
    System.out.println(s.toUpperCase());//字符串中的方法,转换为大写,这种输出方式是在命令提示符下。
    log.println("_ _ _ _ _ _");
    log.println(s.toUpperCase());//与上面转换为大写的方法不同的是,这里的转换是输出到log日志中的。
    log.flush();
   }
   log.println("==="+new Date()+"===");
   log.flush();
   log.close();
  }catch(IOException e){
   e.printStackTrace();
  }
 }
}

原创粉丝点击