• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FilterOutputStream

 
sheri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
what are the possible parameters that can be passed into the construcor of a
FilterInputStream
a.File b.PrintStream c.FileOutputStream d.FileInputStream e.RandomAccessFile

can anybody ans to this Question:
my ans is a:File & b:PrintStream
please help
thanx
sherin
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FilterInputStream(InputStream in) - This is the only constructor available for this class.
Therefore all those params that can be converted to
InputStream in would be valid.
In your case:
File - It extends Object. So u can't use this.
PrintStream - not a subclass of InputStream, but a subclass of OutputStream. The hierarchy is :
outputStream -> FilterOutputStream->
Therefore, we can't use this as well.
FileInputStream - Subclass of InputStream. so, this is OK.
RandomAccessFile - NO ! Coz it does fall under any of the InputStream hierarchy.
Therefore my ans would just be FileInputStream .
Please let me if there is something wrong with this reasoning.
-sampaths77
 
geetha
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sampaths77,
have u tried by passing the FileInputStream into FilterInputStream constructor???becz it is saying that there is no constructor matching for FilterInputStream.and moreover FilterInputStream and FileInputStream belongs to the same level of streams.in that case u can not pass one stream into another.
only the ans could be InputStream.
geetha.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geetha,
please try this:
import java.io.*;
class B extends java.io.FilterInputStream
{
B() throws Exception
{
super (new FileInputStream("yahoo"));
}
public static void main(String[] args)
{
}

}
I am able to compile this piece of code fine.
PLease note that questio just asked:what are the POSSIBLE parameters that can be passed into the construcor of a
FilterInputStream. Since i can do with the above code, I opted for FileInputStream
Plus you say that FileInputStream and FilterInputStream are in the siblings, but this has got nothing to do with the answer coz if u look at the constructor, the i/p param is InputStream. So, the code should compile for all subclasses of imputstream.
Hope this helps
-sampaths77
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic