1 Reply Latest reply on May 8, 2008 12:34 PM by code1234

    FileIO - trailing junk...

    Level 7
      Okay, there's a major weakness with FileIO - if your save file already
      exists, and the data you're saving over it is smaller than its previous
      size, you end up with a bunch of trailing junk at the end of the file, which
      can confuse matters when that file gets loaded up again the next time.
      What's the best way of dealing with this? Is there some way to cut the file
      off at the end of the new data being added? Or is it better to just
      completely delete the file and recreate it from scratch every time? (This
      method probably works the most reliably, but it takes twice as long.)
      Another method I'd heard was to follow your data with a bunch of blank
      space, enough to overwrite any stray data, though determining how MUCH blank
      space varies greatly depending on the situation. Finally, there's the
      possibility of adding a terminator character after the data which you
      program your Open File function to recognize as "End of Data", and ignore
      any junk after that.

      If the first method (cutting off the file) is possible, I'd think that'd be
      the best method. Deleting and recreating it is reliable, but has a drawback
      in terms doubling your save time. The other two methods could work, but
      don't really address the real problem - they both leave the file bloated
      larger than it needs to be, and you end up with extra useless junk (or
      spaces) at the end of your data. What method would you guys think is
      preferable overall?

        • 1. Re: FileIO - trailing junk...
          I generally do the delete and create method. For the projects I've woriked on the size of the text files are fairly small in KB even if they are a lot of pages of text, so they save pretty fast. Even if the speed doubles, that seems a small sacrifice to me for having a clean file.

          So for what it is worth...