java实现图像文件复制功能,运用IO中的FileInputStream等类实现
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImageCopy {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
//创建文件输入输出流
fis=new FileInputStream("G:\\图片\\古剑\\1ec0c41024a4ed3ecb80c448.jpg");
fos=new FileOutputStream("F:\\tests.jpg");
int flag=0;
while((flag=fis.read())!=-1){
fos.write(flag);
}
System.out.println("复制成功");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
if(fis!=null){
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(fos!=null){
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}