Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input stream object

 
Sunil K Bansal
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mahesh
thanks
can you explain why B then
Bansal
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic