2 Replies Latest reply: May 11, 2010 10:39 AM by 807580 RSS

    Delete multiple rows from text file

    629006
      HI,


      i have a text file and i want to remove first few rows from that text file not last rows.
      how can i do that ?


      thanks
        • 1. Re: Delete multiple rows from text file
          Kayaman
          1. Read the file into memory, remove the lines you don't want to and write the lines back to file.

          or

          2. Read the file line by line and write the lines to another file (unless the line is one you want to remove). Then delete the original file and rename the modified to the original.
          • 2. Re: Delete multiple rows from text file
            807580
            because i suspect this is a homework assignment i'm not going to give you the fish, but i will teach you how to fish! =P

            go investigate the Java Standard class called: BufferedReader. Look specifically at the method readLine()

            combine that with a for loop, and an IF-THEN statement to weed out the lines you don't want (or just govern that with the FOR loop's index), and you should be able to figure it out....

            good luck! give it a whirl...