FileWriter简单用法并记录日志
import java.io.*; import java.util.Date; /** * Created by Administrator on 2018/4/6. */ public class TestPrintStream3 { public static void main(String[] args) { TestPrintln(); } private static void TestPrintln() { String str =null; //BufferedReader 将写入数据存放至缓冲区 BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); try { // 创建一个可以往文件中写入字符数据的字符流输出流对象 true :追加内容 FileWriter fw = new FileWriter("F:\\pjection\\src\\main\\java\\io\\test3.txt",true); PrintWriter log = new PrintWriter(fw);//输入流 while ((str = bf.readLine())!=null){ if (str.equalsIgnoreCase("exit")) break; System.out.println(str.toUpperCase()); //将字符串进行大写 log.println("-------------"); log.println(str.toUpperCase()); log.println("----------------"); log.println("====" +new Date()+ "==========="); //打印操作时间 log.flush(); } log.close(); } catch (IOException e) { e.printStackTrace(); } } }