This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

how to change the content of a file

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!