The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Alogrithm for file I/O

Posted by Monte Gardner on February 28, 2001 at 11:48 AM

> Hi Friends,
> I have a problem of removing lines of text from a file. I got the line numbers which i have to remove but I am not sure how would i remove them.
> Can somebody tell me what is the easiest way to do this?
> Thanks
> --Sam

This may not be the easiest way, but Here's an algorithm
I could suggest
I. read each line of your file into a Vector of String objects.
(Each line being an element in the Vector).
II. call Vector.removeElementAt(index) for each line that
you want to remove.

III. At this point you will have a Vector
of Strings containing only the data that you want in the file
IV. Find some way to write each element of the vector back to
the original file.





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us