以IO流的方式,复制图片

public class Seventh {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream("D:\\heima\\psb.jpg");
fos = new FileOutputStream("F:\\luoli.jpg");

byte[] bytes = new byte[1024];
int len;

while ((len = fis.read(bytes)) != -1){
fos.write(bytes,0,len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(fis != null){
try{
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fos != null){
try{
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}
}

猜你喜欢

转载自www.cnblogs.com/YRSWBY2016/p/12019128.html