Delete line of text in text file

I have a text file that I can read fron the console, but I need to be able to delete one line, based on user input, ie copper then deletes the whole line.

1Steel1835.99

2Brass 12810.00

3copper1614.25

4lead1079.50

After all that I then need to do some calcs for each line ie 10*79.50

Can someone point me in the direction of what i should be looking to do..

by the way they are seperated by tabs

Message was edited by:

No_Idear

[489 byte] By [No_Ideara] at [2007-10-3 8:30:04]
# 1

>Can someone point me in the direction of what i should be looking to do..

1) Get the input from the user.

2) Read in a line from your file.

3) Check the line from your file against the user input.

4) Then you can store the line in an array(or an ArrayList).

5) Repeat until you come to the end of the file

6) Make necessary changes to the Strings in the array.

7) Write the Strings to another file.

7studa at 2007-7-15 3:37:03 > top of Java-index,Java Essentials,New To Java...
# 2

3) Check the line from your file against the user input.

How do I do that ?

4) Then you can store the line in an array(or an ArrayList).

5) Repeat until you come to the end of the file

6) Make necessary changes to the Strings in the array.

7) Write the Strings to another file.

But then I will have 2 files when I need to delet it from the original.

No_Ideara at 2007-7-15 3:37:03 > top of Java-index,Java Essentials,New To Java...
# 3

> 3) Check the line from your file against the user

> input.

>

> How do I do that ?

With an if statement.

>

> 7) Write the Strings to another file.

>

> But then I will have 2 files when I need to delet it

> from the original.

Well let's suppose you read in all the data from your file, and then you proceed to write it back to the same file. When you write your first line to the file, it will erase everything that was previously in the file--but you don't care because you have all the data safely stored in an array. But, then your program unexpectedly crashes. Poof! Bye, bye data.

If you use two files, after you are done, you can delete the first file and rename the second file with same name as the first file.

7studa at 2007-7-15 3:37:03 > top of Java-index,Java Essentials,New To Java...
# 4

With an if statement

Like this ?

if }

b = string.matches("(?i).*copper*");

buf.delete(start, end);

Got it for (7) - Makes sense why now....

Message was edited by:

No_Idear

No_Ideara at 2007-7-15 3:37:03 > top of Java-index,Java Essentials,New To Java...