1 package Io; 2 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter; 5 import java.io.FileNotFoundException; 6 import java.io.FileWriter; 7 import java.io.IOException; 8 import java.io.InputStreamReader; 9 import java.io.PrintWriter; 10 11 public class TestHtml { 12 public static void main(String[] args) { 13 BufferedReader br = null; 14 PrintWriter pw = null; 15 try { 16 br = new BufferedReader(new InputStreamReader(System.in)); 17 pw = new PrintWriter(new BufferedWriter(new FileWriter("G:\IoTest\2.html"))); 18 String str = null; 19 while ((str = br.readLine()) != null) { 20 if (str.equals("exit")) { 21 System.out.println("感谢使用"); 22 break; 23 } 24 pw.println(str); 25 } 26 } catch (FileNotFoundException e) { 27 e.printStackTrace(); 28 } catch (IOException e) { 29 e.printStackTrace(); 30 } finally { 31 if (br != null) 32 try { 33 br.close(); 34 } catch (IOException e) { 35 e.printStackTrace(); 36 } 37 } 38 if (pw != null) 39 pw.close(); 40 } 41 }