1 package testio; 2 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter; 5 import java.io.File; 6 import java.io.FileInputStream; 7 import java.io.FileOutputStream; 8 import java.io.IOException; 9 import java.io.InputStreamReader; 10 import java.io.OutputStreamWriter; 11 12 public class Copy { 13 public static void main(String[] args) { 14 File file1 = new File("d:/folder01/file09.txt"); 15 File file2 = new File("d:/folder01/file10.txt"); 16 FileInputStream fis = null; 17 InputStreamReader isr = null; 18 BufferedReader br = null; 19 BufferedWriter bw = null; 20 OutputStreamWriter osw = null; 21 FileOutputStream fos = null; 22 try { 23 fis = new FileInputStream(file1); 24 isr = new InputStreamReader(fis); 25 br = new BufferedReader(isr); 26 27 fos = new FileOutputStream(file2); 28 osw = new OutputStreamWriter(fos); 29 bw = new BufferedWriter(osw); 30 int data; 31 while ((data = br.read()) != -1) { 32 bw.write(data); 33 bw.flush(); 34 } 35 } catch (Exception e) { 36 // TODO Auto-generated catch block 37 e.printStackTrace(); 38 } finally { 39 if (fis != null) { 40 41 try { 42 fis.close(); 43 isr.close(); 44 br.close(); 45 fos.close(); 46 osw.close(); 47 bw.close(); 48 } catch (IOException e) { 49 // TODO Auto-generated catch block 50 e.printStackTrace(); 51 } 52 } 53 } 54 } 55 }