当前页面: 开发资料首页 → J2SE 专题 → SequenceInputStream的问题,求高人
SequenceInputStream的问题,求高人
摘要: SequenceInputStream的问题,求高人
Import java.io.*;
Import java.util.*;
public class Concat {
public static void main(String[] args) throws IOException {
InputStream in;
InputStream FileIn1, FileIn2, bufIn;
OutputStream fileOut;
File fFrom = new File("From", "1.doc");
File fFrom2 = new File("From", "2.doc");
File fTo = new File("To", "3.doc");
fileIn1 = new FileInputStream(fFrom);
fileIn2 = new FileInputStream(fFrom2);
fileOut = new FileOutputStream(fTo);
List inputs = new ArrayList(2);
bufIn = new BufferedInputStream(fileIn1);
inputs.add(bufIn);
bufIn = new BufferedInputStream(fileIn2);
inputs.add(bufIn);
Enumeration files = Collection.enumeration(inputs);
in = new SequenceInputStream(files);
int ch;
while((ch = in.read()) != -1) {
fileOut.write(ch);
}
}
}
请问,我这个函数运行之后,我会把From文件夹下的1.doc文件里的内容拷到To文件夹下的3.doc去,From文件夹里的2.doc却没有一起拷过来,没有达到预期的效果,这是什么原因啊,请高人解释一下,谢谢...
基本没动你的程序,只改了几个小错误
import java.io.*;
import java.util.*;
class Concat {
public static void main(String[] args) throws IOException {
InputStream in;
InputStream fileIn1, fileIn2, bufIn;
OutputStream fileOut;
File fFrom = new File("from", "1.txt");
File fFrom2 = new File("from", "2.txt");
File fTo = new File("to", "3.txt");
fileIn1 = new FileInputStream(fFrom);
fileIn2 = new FileInputStream(fFrom2);
fileOut = new FileOutputStream(fTo);
List inputs = new ArrayList(2);
bufIn = new BufferedInputStream(fileIn1);
inputs.add(bufIn);
bufIn = new BufferedInputStream(fileIn2);
inputs.add(bufIn);
Enumeration files = Collections.enumeration(inputs);
in = new SequenceInputStream(files);
int ch;
while((ch = in.read()) != -1) {
fileOut.write(ch);
}
}
}
运行成功
不好意思,我没装office,所以把你的.doc文件改成了.txt文件
gefengxztg(戈峰) 你好象没改我的程序吧?只改了doc为txt,是不是啊?我找不出其他的改的地方,还有哪里啊?谢谢
我试了下,如果doc改为txt是可以的,不过如果是doc的话,为什么只能把1.doc的内容输进去呢,而2.doc就输不进去,这是什么原因啊?
求救啊...
都可以输进去的
可能是jdk版本的问题
我是jdk1.5-07的
我改的地方: import你大写了
fileIn1 fineIn2定义与使用名字不一致
Collection改成了Collections
应该不会是JDK版本的问题吧
你是不是只把你的txt文件直接重命名成doc的啊?