amend a file : Java Glossary

go to home page A words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 2009-05-11 Roedy Green, Canadian Mind Products
amend a file
There are a number of ways to change the bytes in a file. Here is how to do it, ordered from most to least common.
  1. Read the old file copying to a new file. When you get to the part that should be changed, write new data instead. Then continue copying. When you are done, close both files, delete the old file, and rename the new file to the old, Alternatively rename the old file to *.bak or keep both the old and new files. HunkIO. createTempFile helps by creating the temp file in the same directory as the old file where it can be most easily renamed.
  2. You can use the HunkIO. readEntireFile approach, and read the whole file into RAM, fix it and write it out again in a single I/O.
  3. You can use the append option of FileOutputStream to tack a stream onto the end of an existing file.
  4. You can use RandomAccessFile to patch a few bytes. This technique does not work well when you want to change the length of a chunk of data in the middle of a file. You must leave room for growth when you create the file, or invent some complicated internal file structure the way an SQL engine does to allow records to grow and shrink. If you wanted roll you own, you could implement a hermit crab file. RandomAccessFile is tricky since you have to compute all your own byte offsets.
File I/O Amanuensis to teach you how to do all manner of file, in RAM and remote I/O
I/O
LEDataStream for little-endian i/o
temporary files
UnifiedIO

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/amend.html J:\mindprod\jgloss\amend.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.106]
You are visitor number 11.