This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Input stream object" Watch "Input stream object" New topic
Author

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(System.in);
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
thanks
Bansal
mahesh deshpande
Greenhorn

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");
or
D) RandomAccessFile r = new RandomAccessFile("OutFile","rw");
Sunil K Bansal
Ranch Hand

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

Joined: Sep 29, 2000
Posts: 8521
System.in 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: http://aspose.com/file-tools
 
subject: Input stream object
 
Similar Threads
Applied Reasoning #51
I/0 Quession
scjp (DataInputStream)
DataInputstream
ambigious question about random access file