• 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

RandomAccessFile-----Barry Boone Mock

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is a question from Barry Boone Mock exam
Question 4: What modes are legal for creating a new RandomAccessFile object?
Select all valid answers.
"w"
"r"
"x"
"rw"
"xrw"

The answers are "r" and "rw" I think it should only be "rw" as while using RandomAccessFile if the file is not present and we use "r" mode an IOException will be thrown, however , by using "rw" a new file will be created....am I right???
If any one can explain ....
Thanks in advance..
Wali
[This message has been edited by WaliM (edited July 14, 2000).]
[This message has been edited by WaliM (edited July 14, 2000).]
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. In"rw", you will create a new file of zero length.
In"r", it will throw FileNotFoundException.
[This message has been edited by kevin jia (edited July 15, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the way question is worded it is asking for legal ways of creating RAF object. So both "r", "rw" are legal ways of creating RAF hence ans should be "r" & "rw"
You are right if the file is not available, then with "r" mode it will throw an exception . However in this case we are adding our own assumption, what if the file is not exists.
This question is bit confusing but I will go with "r" & "rw".
Java experts can give tips on handling such questions in the exam.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WaliM
Siva has put it rightly. To put it simply your motto in the exam should be to- 'Read the Lines carefully & Read between the Lines, but NOT BEYOND THEM!'
One can add innumerable 'what if' conditions & then the meaning of any sentence can be altered to suit one's thoughts....so Read between the lines but DO NOT ADD any lines !
regards
--Shiny
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys..
Wali
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not comfortable , it is clear cut asking for creating new RAF , which is only possible with "rw" mode.then how can we go for "r " mode.
IMHO it is a mistake with question.If i am wrong can anybody explain me.
thanx,
DS
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deepak,
Here is what API documentation says


The mode argument must either be equal to "r" or "rw", indicating that the file is to be opened for input only or for both input and output, respectively. The write methods on this object will always throw an IOException if the file is opened with a mode of "r". If the mode is "rw" and the file does not exist, then an attempt is made to create it. An IOException is thrown if the file argument refers to a directory.


Now, let's read the question again. What modes are legal for creating a new RandomAccessFile object? . As pointed out before, do not read beyond what the question states. Clearly "r" and "rw" are legal modes for creating a new RAF object.
Ajith
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, Ajith
now i got it. but its very difficult to go on language . Are we supposed to face these kind questions in exams also....
thanx again ,
DS
 
You can't have everything. Where would you put it?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic