1 Reply Latest reply: Mar 27, 2008 1:07 PM by DrClap RSS

    To delete Data From a file

      i want to delete lines from a file after reading the line. the next time i read the file i should find a unread line as the 1st line of the file.
      how do i do tat? this is very similar to delete from table name query in sql. but i have to do this with java and txt files. how do i code this??
        • 1. Re: To delete Data From a file
          You can't delete part of a file. The way to do that in general is like this:

          1. Read a line.

          2. If you want to delete it, do nothing. Otherwise write it to a new file.

          3. Repeat until end-of-file.

          After you've finished all that, the new file will contain everything you didn't want to delete. Now delete the original file and rename the new file to have its name.