1 package com.io; 2 /** 3 * 将图片复制一份 4 * 2019-08-04 5 * @author L 6 */ 7 import java.io.DataInputStream; 8 import java.io.DataOutputStream; 9 import java.io.FileInputStream; 10 import java.io.FileNotFoundException; 11 import java.io.FileOutputStream; 12 import java.io.IOException; 13 import java.io.InputStream; 14 import java.io.OutputStream; 15 16 public class Picture { 17 public static void main(String[] args) { 18 DataInputStream dis=null; 19 InputStream is=null; 20 21 DataOutputStream dos=null; 22 OutputStream os=null; 23 24 try { 25 is=new FileInputStream("D:\star.jpg"); 26 dis=new DataInputStream(is); 27 28 os=new FileOutputStream("D:\myPicture.jpg"); 29 dos =new DataOutputStream(os); 30 int num; 31 while((num=dis.read())!=-1) { 32 dos.write(num); 33 } 34 System.out.println("复制完成!"); 35 } catch (FileNotFoundException e) { 36 // TODO Auto-generated catch block 37 e.printStackTrace(); 38 } catch (IOException e) { 39 // TODO Auto-generated catch block 40 e.printStackTrace(); 41 }finally { 42 try { 43 dos.close(); 44 os.close(); 45 dis.close(); 46 is.close(); 47 } catch (IOException e) { 48 // TODO Auto-generated catch block 49 e.printStackTrace(); 50 } 51 } 52 53 } 54 }