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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 蓝枫 中级黑马   /  2014-4-5 17:15  /  552 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. 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>();

  8.         v.add(new FileInputStream("c:\\1.txt"));
  9.                 v.add(new FileInputStream("c:\\2.txt"));
  10.                 v.add(new FileInputStream("c:\\3.txt"));

  11.                 Enumeration<FileInputStream> en = v.elements();

  12.                 SequenceInputStream sis = new SequenceInputStream(en);

  13.                 FileOutputStream fos = new FileOutputStream("c:\\4.txt");

  14.                 byte[] buy = new byte[1024];

  15.                 int len = 0;

  16.                 while((len=sis.read(buy))!=-1)
  17.                 {
  18.                         fos.write(buy,0,len);
  19.                 }
  20.                 fos.close();
  21.                 sis.close();



  22.         }

  23. }

  24. 1.txt
  25. 1
  26. 11
  27. 111

  28. 2.txt
  29. 2
  30. 22
  31. 222
  32. 2222

  33. 3.txt
  34. 3
  35. 33
  36. 333
  37. 3333

  38. 输出的4.txt
  39. 1
  40. 11
  41. 1112
  42. 22
  43. 222
  44. 22223
  45. 33
  46. 333
  47. 3333

  48. 怎么是这样,不应该是
  49. 1
  50. 11
  51. 111
  52. 2
  53. 22
  54. 222
  55. 2222
  56. 3
  57. 33
  58. 333
  59. 3333
  60. 这样的吗?谁帮忙解释一下,怎么回事?
复制代码

0 个回复

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