Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RandomAccess File

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any reply!!!
 
Savithri Devaraj
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys for your kind help...
Wali
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic