package com.neuedu.list;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 使用FileInputStream和FileOutputStream实现对图片的复制粘贴
* @author geng_
*
*/
public class CopyAndPast {
public static void main(String[] args) {
File reader = new File("E:/HeBe.jpg");
File writer = new File("F:/HeBe.jpg");
FileInputStream fis = null;
try {
fis = new FileInputStream(reader);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
BufferedInputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(writer);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] b = new byte[1024];
int len = -1;
try {
while((len = bis.read(b))!=-1){
bos.write(b,0,len);
bos.flush();
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
bos.close();
fos.close();
bis.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
使用FileInputStream和FileOutputStream实现对图片的复制粘贴
最新推荐文章于 2024-02-17 16:23:14 发布