• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

how to change the content of a file

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I want to change the content of a file,not all the contents but some slite modifications to the file.Can anyone help me to get a code to do this?
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we need some more details - for example, what is the file name (or would you prefer to specify it on the command line), what is the type of file and its contents (e.g. plain text, XML, binary, compressed archive) and what sort of changes do you need to make?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short, you can overwrite bytes in the middle of a file, but you can't easily replace old stuff with new stuff of a different length. So change and append are easy, but insert and delete are tough. It's common to read all of the old file and write a totally new one with the same or changed content.

See RandomAccessFile if you can be sure the data length doesn't change. Otherwise just read and write with whatever IO works with your data.
[ March 16, 2006: Message edited by: Stan James ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic