A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© iFmmer 中级黑马   /  2015-6-18 22:46  /  443 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. import java.io.*;


  2. public class testPhotoCopy {
  3.         public static void main(String args[]){
  4.                 FileInputStream fis = null;
  5.                 FileOutputStream fos = null;
  6.                 try {
  7.                         fis = new FileInputStream("D:\\ashk_wnd.bmp");
  8.                         fos = new FileOutputStream("c:\\ashk_wnd.bmp");

  9.                         int num = 0;

  10.                         byte[] buf = new byte[1024];
  11.                        
  12.                         while ((num = fis.read(buf))!=-1){
  13.                                 fos.write(buf,0,num);
  14.                         }
  15.                        
  16.                 } catch (IOException e) {
  17.                         throw new RuntimeException("写入图片失败");
  18.                 } finally{
  19.                         try {
  20.                                 if(fis!=null)
  21.                                         fis.close();
  22.                         } catch (IOException e) {
  23.                                 throw new RuntimeException("关闭输入流失败");
  24.                         }
  25.                         try{
  26.                                 if(fis!=null)
  27.                                         fos.close();
  28.                         } catch(IOException e){
  29.                                 throw new RuntimeException("关闭输出流失败");
  30.                         }
  31.                 }

  32.         }
  33. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马