1 package test.stream; 2 3 import java.io.FileInputStream; 4 import java.io.FileNotFoundException; 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 /** 8 * 通过文件流拷贝文件 9 * @author Frost.Yen 10 * @E-mail 871979853@qq.com 11 * @date 2016年4月13日 12 */ 13 public class TestStream02 { 14 public static void main(String[] args) { 15 FileInputStream fis = null; 16 FileOutputStream fos = null; 17 18 try { 19 fis = new FileInputStream("E:\JAVA\Examples\To Learn\src\test\stream\1.jpg"); 20 fos = new FileOutputStream("E:\JAVA\Examples\To Learn\src\test\stream\a.jpg"); 21 byte[] buf = new byte[1024]; 22 int len = 0; 23 while((len=fis.read(buf))>=0){ 24 fos.write(buf, 0, len); 25 } 26 } catch (FileNotFoundException e) { 27 e.printStackTrace(); 28 } catch (IOException e) { 29 e.printStackTrace(); 30 } finally { 31 try { 32 if(fis!=null) fis.close(); 33 } catch (IOException e) { 34 e.printStackTrace(); 35 } 36 try { 37 if(fos!=null) fos.close(); 38 } catch (IOException e) { 39 e.printStackTrace(); 40 } 41 } 42 43 } 44 }