//在用SequenceInputStream连接两个文件中的内容时出现了问题,只有第一个文件的内容,后面的一个文件
//的内容没法读进去,JAVA菜鸟。求解 谢谢!import java.io.File;
import java.io.FileInputStream;
import java.io.SequenceInputStream;
public class TestSequence { 
public static void main(String[] args) throws Exception {
FileInputStream fis1=null;
fis1=new FileInputStream(new File("d:/2.txt"));
FileInputStream fis2=null;
fis2=new FileInputStream(new File("d:/1.txt"));
SequenceInputStream seq = new SequenceInputStream(fis1, fis2);
byte[] b = new byte[20];
seq.read(b);
System.out.println(new String(b, 0, b.length));
seq.close();
}} 木有人啊木有人 - -、

解决方案 »

  1.   

    你只读了一行应该修改下:import java.io.File;
    import java.io.FileInputStream;
    import java.io.SequenceInputStream;
    public class TestSequence {  
    public static void main(String[] args) throws Exception {
    FileInputStream fis1=null;
    fis1=new FileInputStream(new File("d:/2.txt"));
    FileInputStream fis2=null;
    fis2=new FileInputStream(new File("d:/1.txt"));
    SequenceInputStream seq = new SequenceInputStream(fis1, fis2);
    byte[] b = new byte[20];

    while(seq.read(b)!=-1){
    System.out.println(new String(b, 0, b.length));
    }

    seq.close();
    }}
      

  2.   

    红色字体不好用啊 , 就是while循环处
      

  3.   

    简单的做法就是用流读出一行 将这行信息放入一个StringBuffer内 
    你把两个文件的内容都放在StringBuffer内 然后写入一个新的文件内
      

  4.   

    你只读取了一次,就连第一个文件都可能没有读完。这样改改就可以了。while(seq.read() != -1)
            {
                seq.read(b);
                System.out.println(new String(b, 0, b.length));
            }
      

  5.   


    正解,读文件的时候一般都要写while(){}语句的。这点要记住了。