- /**
- * 功能流SequenceInputStream功能演示 功能,可以将多个流放到一起进行合流
- * 程序功能:将11.txt、22.txt、33.txt合并到44.txt
- *
- * @throws Exception
- * @since JDK 1.6
- */
- public void suquenceDemo() throws Exception {
- Vector<InputStream> v = new Vector<InputStream>();
- v.add(new FileInputStream("c:\\11.txt"));
- v.add(new FileInputStream("c:\\22.txt"));
- v.add(new FileInputStream("c:\\33.txt"));
- Enumeration<InputStream> en = v.elements();
- SequenceInputStream sis = new SequenceInputStream(en);
- FileOutputStream fos = new FileOutputStream("c:\\44.txt");
- int len = 0;
- byte[] bf = new byte[1024];
- while ((len = sis.read(bf)) != -1) {
- fos.write(bf, 0, len);
- }
- fos.close();
- sis.close();
- }
复制代码 |
|