Javaファイルの読み込みと書き込み



package com.manze.stu;
 import java.io.*;   
   
 public class IOTest {  
  
      public static void samples() throws IOException {  
  
            //1.                
   
            BufferedReader in = new BufferedReader(new FileReader("D:\\info.txt" ));  
             String s="",s2="";
             while((s=in.readLine())!=null)
                   	 s2+=s+"
"; in.close(); //2. StringReader in1 = new StringReader(s2); int c; while ((c = in1.read()) != -1) System .out.print((char)c); //3. try { BufferedReader in2 = new BufferedReader(new StringReader(s2)); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("D:\\IODemo.txt" ))); int lineCount = 1; while ((s = in2.readLine()) != null ) out1.println(s); out1.close(); } catch (EOFException e) { System .err.println("End of stream" ); } } public static void main(String[] arg) { try { IOTest.samples(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }