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).]
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.
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
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
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
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).