1

Possible Duplicate:
Java - Find a line in a file and remove

ChavezJan2012   SLC   1.25
ChavezFeb2012   SLC   0.25
ChavezMar2012   SLC   1.25

I have this data written in a text file using java and i wanted to delete one row out of the 3 rows in my file. I'm still trying my best to find a solution as of the moment using an arrayList.

ChavezJan2012   SLC   1.25
ChavezMar2012   SLC   1.25

Desired result after the deletion. Please help, thanks.......

Community
  • 1
  • 1
simple pogi87x
  • 21
  • 1
  • 1
  • 4

2 Answers2

0

The only way to do is create a temporary file. Write all the text in that file except the line to be omitted. And rename that temporary file to old file name.

dejavu
  • 3,236
  • 7
  • 35
  • 60
0

You can make a loop with indexing i+3 for example:

for (int i=0 i < arraylist.size(); i+3){

writeToFile.arraylist.get(i);
writeToFile.arraylist.get(i+2);

}
java_xof
  • 439
  • 4
  • 16