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

© fmi110 高级黑马   /  2015-10-4 15:39  /  325 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

s
  1. package demo.io;

  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;

  6. public class IODemo5 {

  7.         /**
  8.          * d:\\EditPlus.zip 到 C:盘
  9.          *
  10.          * @throws Exception
  11.          */
  12.         public static void main(String[] args) throws Exception {
  13.                 File src = new File("d:\\EditPlus.zip");
  14.                 FileInputStream fin = null;
  15.                 FileOutputStream fos = null;
  16.                 fin = new FileInputStream(src);
  17.                 fos = new FileOutputStream("c:\\copy_EditPlus.zip");

  18.                 // CopyByByte(fin, fos);
  19.                 copyByBuf(fin, fos);
  20.         }

  21.         private static void copyByBuf(FileInputStream fin, FileOutputStream fos)
  22.                         throws IOException {
  23.                 byte[] buf = new byte[1024];
  24.                 int len = 0;
  25.                 while((len = fin.read(buf))!=-1){
  26.                         fos.write(buf,0,len);
  27.                 }
  28.                 System.out.println("done");
  29.                 fin.close();
  30.                 fos.close();
  31.         }

  32.         private static void CopyByByte(FileInputStream fin, FileOutputStream fos)
  33.                         throws IOException {
  34.                 int by = 0;
  35.                 while ((by = fin.read()) != -1) {
  36.                         fos.write(by);
  37.                 }
  38.                 fos.flush();// 函数内容为空,调用其实没意思
  39.                 System.out.println("done");
  40.                 fin.close();
  41.                 fos.close();
  42.         }

  43. }
复制代码


2 个回复

倒序浏览
你好多黑马币啊
回复 使用道具 举报
lostyou 发表于 2015-10-4 16:46
你好多黑马币啊

看我的主题个数说明了一切
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马