黑马程序员技术交流社区

标题: 合并流? [打印本页]

作者: 李柯    时间: 2012-4-14 06:58
标题: 合并流?
  1. <p>import java.io.*;
  2. import java.util.*;
  3. class  SequenceDemo
  4. {
  5. public static void main(String[] args) throws IOException
  6. {
  7.   Vector<FileInputStream> v = new Vector<FileInputStream>();</p><p>  v.add(new FileInputStream("c:\\1.txt"));
  8.   v.add(new FileInputStream("c:\\2.txt"));
  9.   v.add(new FileInputStream("c:\\3.txt"));</p><p>  Enumeration<FileInputStream> en = v.elements();//返回此向量的组件的枚举。</p><p>  SequenceInputStream sis = new SequenceInputStream(en);</p><p>  FileOutputStream fos = new FileOutputStream("c:\\4.txt");</p><p>  byte[] buf = new byte[1024];</p><p>  int len = 0;</p><p>  while ((len=sis.read(buf))!=-1)
  10.   {
  11.    fos.write(buf,0,len);
  12.   }
  13.   
  14.   fos.close();
  15.   sis.close();
  16.   
  17. }
  18. }</p>
  19. <p> </p>
复制代码
本程序运行时出先如下错误:Exception in thread "main" java.io.FileNotFoundException: c:\1.txt (系统找定的文件。)
谁帮忙看看错在哪了?找了很长时间一直没找到。

作者: 张小庆    时间: 2012-4-14 07:12
楼主,你这个是根本没有创建文件啊,你没看毕老师视频里面是手动创建了1,2,3,然后才写的这个代码吗
作者: 刘占月    时间: 2012-4-14 09:25
这个要手动创建文件的。要不然你让程序去读取谁呢。。
作者: 蒋亮    时间: 2012-4-14 15:53
本程序运行时出先如下错误:Exception in thread "main" java.io.FileNotFoundException: c:\1.txt (系统找定的文件。)
错误提示很明显啊,硬盘上没有指定的文件啊,你在c盘下手动创建一个1.txt文件就行了啊




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