-4

I am trying to combine 4 files into a single file,using SequenceInputStream and LinkedList as data structure.

My error is

Exception in thread "main" java.lang.ClassCastException: java.io.FileInputStream cannot be cast to java.util.Enumeration at faizal.Address.main(Address.java:21)

import java.io.*;

import java.util.*;



public class Address{
    public static void main(String[] args) throws Exception {
        FileInputStream f1 = new FileInputStream("E://Ass.java");
        FileInputStream f2 = new FileInputStream("E://Ass1.java");
        FileInputStream f3 = new FileInputStream("E://abc.txt");
        FileInputStream f4 = new FileInputStream("E://ad.txt");
        LinkedList al = new LinkedList();
        al.add(f1);
        al.add(f2);
        al.add(f3);
        al.add(f4);
        Collections.synchronizedList(al);
        Enumeration e = (Enumeration) al.element();
        SequenceInputStream sq = new SequenceInputStream((Enumeration<? extends InputStream>) al);
        int i = 0;
        while((i=sq.read())!=-1){
            System.out.print((char)i);
        }


    }
}
SatyaTNV
  • 4,137
  • 3
  • 15
  • 31
Faizal F
  • 1
  • 1

1 Answers1

0

If I understand your goal: you have 4 files, you want to concatenate. Format inside files doesn't matter. The way you use is useless (sic), and cant work, because your program cant guess magicly what is inside.

Then, just :

  • read each one:

Reading a plain text file in Java

  • I suppose it is texte (txt, java) : just append to String, and write in one shot to a file, like this:

How do I create a file and write to it in Java?

  • or, write each one, and append to the file

How to append text to an existing file in Java

Community
  • 1
  • 1