黑马程序员技术交流社区

标题: 使用自定义数组拷贝文件或使用高效流拷贝文件 [打印本页]

作者: 孙广浩    时间: 2015-11-14 21:31
标题: 使用自定义数组拷贝文件或使用高效流拷贝文件
  1. package com.heima.test;

  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;

  7. public class Test1_fileInPutStream {

  8.         /**
  9.          * @param args
  10.          * @throws IOException
  11.          */
  12.         public static void main(String[] args) throws IOException {
  13.                 //FileInputStream fis = new FileInputStream("xxx.txt");                                                                                 //使用自定义数组拷贝文件                     
  14.                 BufferedInputStream bis = new BufferedInputStream(new FileInputStream("xxx.txt"));  //使用高效流拷贝文件
  15.                 //FileOutputStream fos = new FileOutputStream("copy.txt");
  16.                 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy.txt"));
  17.                 int a ;
  18.                 while ((a = bis.read()) != -1) {
  19.                         bos.write(a);
  20.                 }
  21.                 bis.close ();
  22.                 bos.close ();
  23.         }
  24. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2