- package com.test;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.SequenceInputStream;
- import java.util.Enumeration;
- import java.util.Vector;
- public class Test1 {
- public static void main(String[] args) {
- //将多个文件的内容整个成一个文件
- Vector<FileInputStream> v=new Vector<FileInputStream>();
- try {
- v.add(new FileInputStream("e:\\1.txt"));//添加多个文件
- v.add(new FileInputStream("e:\\2.txt"));
- v.add(new FileInputStream("e:\\3.txt"));
- Enumeration<FileInputStream> en=v.elements();
- SequenceInputStream sis=new SequenceInputStream(en);
- FileOutputStream out=new FileOutputStream("e:\\4.txt");
- byte[] by=new byte[1024];
- int len=0;
- try {
- while((len=sis.read(by))!=-1){
- out.write(by,0,len);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- sis.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- }
复制代码 |
|