• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Input stream object

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mahesh
thanks
can you explain why B then
Bansal
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic