File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Input stream object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Input stream object" Watch "Input stream object" New topic

Input stream object

Sunil K Bansal
Ranch Hand

Joined: Jan 04, 2001
Posts: 62
hi guys I have doubt in this question
which I have seen in a mock exam
Which of the following will compile without error?
A) File f = new File("/","autoexec.bat");
B) DataInputStream d = new DataInputStream(;
C) OutputStreamWriter o = new OutputStreamWriter(System.out);
D) RandomAccessFile r = new RandomAccessFile("OutFile");
According to me right answers r : A,C,D
but the exam says rihgt answers r : A,B,C
how it is B and not D
please explain me
mahesh deshpande

Joined: Oct 26, 2000
Posts: 19
hi sunil
Please see the constructor for the RandomAccessfile().
it should have been like this i.e. u have to specify access mode whether it is read only or read and write both
D) RandomAccessFile r = new RandomAccessFile("OutFile" "r");
D) RandomAccessFile r = new RandomAccessFile("OutFile","rw");
Sunil K Bansal
Ranch Hand

Joined: Jan 04, 2001
Posts: 62
Hi Mahesh
can you explain why B then
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521 takes input from the console (user keys it in). You have to wait till runtime to see if that input is valid. I certainly would not use that without putting it in a try/catch block.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Input stream object
It's not a secret anymore!