You can read from the original file, write to a temporary file only those records that do not match the specified ID and then at the end replace the original file with the new temporary file.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
public class Demo{
public static void main(String[] argv)
throws Exception{
Writer output = new BufferedWriter(new FileWriter("fixed.txt"));
BufferedReader freader =
new BufferedReader(new FileReader("orinal.txt"));
String s;
while ((s=freader.readLine())!=null){
String tokens[] = s.split(",");
String id = f[0];
String name = f[1];
// check against the ID or ID's you don't want. If the current ID is not the one
// you don't want then write it to the output file
if (!id.equals("00001") {
output.write(s + "\n");
}
}
freader.close();
output.close();
}
}
ferrari fan
2009-08-04 13:43:02