This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RandomAccess File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RandomAccess File" Watch "RandomAccess File" New topic
Author

RandomAccess File

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
With which I/O operation can we append. update a file?

RandomAccessFile(),
OutputStream()
DataOutputStream()
The answer is RandomAccessFile , I think it should be OutputStream as it has a constructor
OutputStream(String name, boolean append)
If someone can explain
Wali
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
any reply!!!
Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
Originally posted by WaliM:
With which I/O operation can we append. update a file?

RandomAccessFile(),
OutputStream()
DataOutputStream()
The answer is RandomAccessFile , I think it should be OutputStream as it has a constructor
OutputStream(String name, boolean append)
If someone can explain
Wali

I think RandomAccessFile is correct as that is the only method to update anything in the file (in a non-sequential manner). All streams, readers and writers access file sequentially. Append can be done by all of them.
Any comments?
Savithri
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I think u can modify a file using all three above.U cannot use a OutputStream,but a subclass of it,namely FileOutputStream.Random AccessFile is used for non sequential access and the other two will be used for sequential access.
I hope I have been clear enough.
------------------
Come on in !! Drinks are on the house in the Big Moose Saloon !!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Oh yes,appending can be done using all three also,as u can pass a FileInputStream cons. in the append mode to a DataInputStream.
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
Originally posted by WaliM:
With which I/O operation can we append. update a file?

RandomAccessFile(),
OutputStream()
DataOutputStream()
The answer is RandomAccessFile , I think it should be OutputStream as it has a constructor
OutputStream(String name, boolean append)
If someone can explain
Wali

OutputStream is an abstract class. What's more I would risk the theory that it has nothing to do with files as well as the DataOutputStream. Therefore the only answer that makes sense is RandomAccessFile. OutputStream has no constructor with the signature OutputStream(String name, Boolean append), you might be thinking about FileOutputStream.

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks a lot guys for your kind help...
Wali
 
GeeCON Prague 2014
 
subject: RandomAccess File