黑马程序员技术交流社区
标题:
IO流练习-----图片拷贝代码
[打印本页]
作者:
iFmmer
时间:
2015-6-18 22:46
标题:
IO流练习-----图片拷贝代码
import java.io.*;
public class testPhotoCopy {
public static void main(String args[]){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("D:\\ashk_wnd.bmp");
fos = new FileOutputStream("c:\\ashk_wnd.bmp");
int num = 0;
byte[] buf = new byte[1024];
while ((num = fis.read(buf))!=-1){
fos.write(buf,0,num);
}
} catch (IOException e) {
throw new RuntimeException("写入图片失败");
} finally{
try {
if(fis!=null)
fis.close();
} catch (IOException e) {
throw new RuntimeException("关闭输入流失败");
}
try{
if(fis!=null)
fos.close();
} catch(IOException e){
throw new RuntimeException("关闭输出流失败");
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2