SequenceInputStream is not taking enumeration argument
I am new to java technology.So i was going through SequenceInputStreamI
tried below code,but i am not able to find the exact problem, kindly some
one help
public class SequenceInput {
public static void main(String[] args) throws IOException {
Enumeration e=new MyEnum();
SequenceInputStream sin=new SequenceInputStream(e);
DataInputStream din=new DataInputStream(sin);
String s="";
while(null !=s) {
s=din.readLine();
if(null !=s) {
System.out.println(s);
}
}
din.close();
// new Vector().elements();
}
//Enumeration Class
public class MyEnum implements Enumeration{
InputStream in[];
int i=0;
public MyEnum(){
try {
in=new InputStream[] {new FileInputStream("src/a1.txt"),new
FileInputStream("src/a2.txt"),new
FileInputStream("src/a3.txt"),new FileInputStream("src/a4.txt")};
}
catch(Exception e) {
}
}
@Override
public boolean hasMoreElements() {
if(in.length<=4) {
return true;
}
else
return false;
}
@Override
public Object nextElement() {
return in[i++];
}
}
}
In this line Enumeration e=new MyEnum(); it is showing - No enclosing
instance of type SequenceInput is accessible. Must qualify the allocation
with an enclosing instance of type SequenceInput (e.g. x.new A() where x
is an instance of SequenceInput).
I am not getting the exact problem.
Else i have used new Vector().add() and it was working fine with
sequenceInputStream. Wanted to know about above code..Where am i making
mistake.
Thanks in advance.
No comments:
Post a Comment