• Post Reply Bookmark Topic Watch Topic
  • New Topic

update mode in file handling

 
PriyaRajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
Is there any way to open an existing text file in update mode(not append mode)?
I want to read the contents of the file and make changes to it.
Thank u,
Priya
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want RandomAccessFile. You can read and/or write anywhere in the file (or append to the end) with that.
You can't use streams or readers/writers directly on a RandomAccessFile. However, you can read some or all of the file into a byte array, do stream operations on a ByteArrayInputStream/ByteArrayOutputStream, then write some or all of the bytes back to the RandomAccessFile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!