正常循环
1 import java.io.*; 2 import java.util.*; 3 4 public class MyPrintStreamTest3{ 5 public static void main(String[] args) { 6 BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); 7 String s = null; 8 9 try 10 { 11 PrintWriter log = new PrintWriter( new FileWriter("D://javalearning//MYIO//log4j.txt",true) ); 12 while((s = br.readLine())!=null){ 13 if (s.equalsIgnoreCase("exit")) break; 14 System.out.println(s.toUpperCase()); 15 log.println("--------"); 16 log.println(s.toUpperCase()); 17 log.flush(); 18 } 19 log.println("=="+new Date()+"=="); 20 log.flush(); 21 log.close(); 22 23 } 24 catch (IOException e) 25 { 26 e.printStackTrace(); 27 } 28 } 29 }
死循环
1 import java.io.*; 2 import java.util.*; 3 4 public class MyPrintStreamTest3{ 5 public static void main(String[] args) { 6 BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); 7 String s = null; 8 9 try 10 { 11 PrintWriter log = new PrintWriter( new FileWriter("D://javalearning//MYIO//log4j.txt",true) ); 12 s = br.readLine(); 13 while(s!=null){ 14 if (s.equalsIgnoreCase("exit")) break; 15 System.out.println(s.toUpperCase()); 16 log.println("--------"); 17 log.println(s.toUpperCase()); 18 log.flush(); 19 } 20 log.println("=="+new Date()+"=="); 21 log.flush(); 22 log.close(); 23 24 } 25 catch (IOException e) 26 { 27 e.printStackTrace(); 28 } 29 } 30 }
时间: 2024-11-05 03:42:00