TrainBeaser for iPhone
The moose likes I/O and Streams and the fly likes Writing byte to a particular location in a file header Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Writing byte to a particular location in a file header" Watch "Writing byte to a particular location in a file header" New topic
Author

Writing byte to a particular location in a file header

john kalaigian
Greenhorn

Joined: Nov 20, 2001
Posts: 15
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

Joined: Jan 02, 2001
Posts: 783
The only way to do this is to use java.io.RandomAccessFile and use the "rw" mode.
john kalaigian
Greenhorn

Joined: Nov 20, 2001
Posts: 15
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

Joined: Nov 20, 2001
Posts: 15
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
 
IntelliJ Java IDE
 
subject: Writing byte to a particular location in a file header
 
Threads others viewed
Converting byte to BitSet
POSTing from applet to servlet
Problem with searching for a file which is in the zip file
Understanding the DB file
Reading a large text file ,modifying it and writing it to another file
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com