• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Writing byte to a particular location in a file header

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I think she's lovely. It's this tiny ad that called her crazy:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic