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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 罗中扬 中级黑马   /  2014-6-10 21:33  /  713 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. /**
  2. * 拷贝单个文件的代码
  3. * @author luo
  4. *
  5. */
  6. public class FileStramDome {
  7.         public static void main(String[] s) {
  8.                 FileOutputStream fos = null;
  9.                 FileInputStream fis = null;
  10.                 try {
  11.                         fos = new FileOutputStream("bbb.bmp"); //原文件名和路径
  12.                         fis = new FileInputStream("D://aaa.bmp");  //拷贝的文件名
  13.                         byte[] bs = new byte[1024];
  14.                         int len = 0;
  15.                         while ((len = fis.read(bs)) != -1) {
  16.                                 fos.write(bs, 0, len);

  17.                         }

  18.                 } catch (Exception e) {
  19.                 } finally {
  20.                         try {
  21.                                 if (fos != null) {
  22.                                         fos.close();
  23.                                 }
  24.                         } catch (IOException e) {
  25.                                 e.printStackTrace();
  26.                         }
  27.                         try {
  28.                                 if (fis != null) {
  29.                                         fis.close();
  30.                                 }
  31.                         } catch (IOException e) {
  32.                                 e.printStackTrace();
  33.                         }

  34.                 }

  35.         }
  36. }
复制代码

0 个回复

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