//Print流:从控制台上写入一些信息,再写入test.txt文件中,模拟日志系统
import java.util.*;
import java.io.*;
public class TestPrintStream {
public static void main(String[] args) {
String s = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
FileWriter fw = new FileWriter("F://javashipin//test.log", true); //Log4J
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.flush();
}
log.println("==="+new Date()+"===");
log.flush();
log.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.util.*;
import java.io.*;
public class TestPrintStream {
public static void main(String[] args) {
String s = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
FileWriter fw = new FileWriter("F://javashipin//test.log", true); //Log4J
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.flush();
}
log.println("==="+new Date()+"===");
log.flush();
log.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}