天天看點

複制圖檔

import java.io.FileInputStream;

 import java.io.FileOutputStream;

 import java.io.IOException;



 public class FileIO {

 public static void main(String[] args) {

FileOutputStream fos=null;

FileInputStream fis=null;


try{

fos=new FileOutputStream("G:\\my.bmp");

fis=new FileInputStream("G:\\process.png");

byte[] buf=new byte[1024];

int len=0;

while((len=fis.read(buf))!=-1){

fos.write(buf,0,len);

}

}catch(IOException e){

throw new RuntimeException("複制檔案失敗");

}finally{

try{

if(fis!=null){

fis.close();

}

}catch (IOException e2) {

throw new RuntimeException("讀取檔案失敗");

}


try{

if(fos!=null){

fos.close();

}

}catch (IOException e2) {

throw new RuntimeException("寫入檔案失敗");

}

}

}

 }