• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing byte to a particular location in a file header  RSS feed

 
john kalaigian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have a file with a header which I've read and know the exact location of the particular element that I want to read. What I want to do now is overwrite that particular element of the file with a byte representation of a String. How do i do this, and also without creating a new file, cause I'm using a
FileInStream->BufferedInStream->DataInStream
to do the reading and I don't want to create a brand new
FileOutStream->BufferedOutStream->DataOutStream
to do the writing. I want to just overwrite particular elements in the file header. Thanks, John
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way to do this is to use java.io.RandomAccessFile and use the "rw" mode.
 
john kalaigian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here's my code if it would help out. I just wanna have you take a look to see if it really has to be done with RandomAccessFile

What I wanna do is not go into a particular header line say (0020,0010) which is group 0020, and overwrite element 0010, so somewhere in my case statement I will have:

Now here's the problem. I don't know where to start writing this data because up in getNextDataElement(DataInStream) I read from the DataInStream starting at 0 and going up to the length provided in the header. Now that I'm sitting in the retrieveData method I'm just parsing through the groups and reading the bytes provided in my byte buffer. Where and how do I write my new String into the file without creating a new file - just modifying the bytes specified in the group. Hope this is a little more comprehensive.
John
 
john kalaigian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the above. I wrote:
What I wanna do is not go into a...

It should be
What I wanna do is go into a...

John
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!