| 本帖最后由 刘勇强 于 2013-5-30 01:06 编辑 
 lz你的代码里 把aa.txt内容写到aa.txt是看不出效果的 你写回了原文件里
 
 public class Ww {
 
 /**
 * @param args
 * @throws IOException
 */
 public static void main(String[] args) throws IOException {
 // TODO Auto-generated method stub
 FileInputStream fis = new FileInputStream("D:\\aa.txt");
 BufferedOutputStream bos = new BufferedOutputStream(
 new FileOutputStream("D:\\aaa.txt"));
 
 int by= 0;
 while((by=fis.read())!=-1)
 {
 bos.write(by);
 }
 
 bos.close();
 fis.close();
 
 }
 
 }
 这是改过后的代码 从aa.txt 写到aaa.txt ,直接从输入流读取到输出流,没必要用一个字节数组中转.
 
 之所以要把FileInputStream打包成BufferedInputStream, 用毕老师的话就是,你直接用FileInputStream是读一个字节往硬盘写一次,效率太低,而BufferedInputStream是创建一个内部缓冲区,读完后最后写道文件里 提高效率.  我上面的代码是可以打包FileInputStream 用BufferedInputStream的
 |