1つの パッケージcom.io。 2 / ** 3 *将图片复制一份 4 * 2019年8月4日 5 * @author L 6 * / 7 インポートにjava.io.DataInputStream。 8 インポートjava.io.DataOutputStreamのメソッド。 9 インポートjava.io.FileInputStream。 10 インポートjava.io.FileNotFoundException。 11 インポートjava.io.FileOutputStreamは。 12 輸入にjava.io.IOException; 13 輸入java.io.InputStreamを。 14 輸入に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 }