i have a text file with database table data in it and im trying to delete a part of the table. this is what is in the file:
name= john
name= bill
name= tom
name= bob
name= mike
here is my java code that compiles and runs, but the output is not what i expected and stuck.
import java.io.*;
public class FileUtil {
public static void main(String args[]) {
try {
FileInputStream fStream = new FileInputStream("\\test.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
while (in.ready()) {
//System.out.println(in.readLine());
String line = in.readLine();
String keyword = "name="; //keyword to delete in txt file
String newLine=line.replaceAll(keyword,""); //delete lines that say name=
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("testEdited.txt"));
out.write(newLine.getBytes());
out.close();
}
in.close();
} catch (IOException e) {
System.out.println("File input error");
}
}
}
the output in the testEdited file is this:
mike
obviously i want to be left with just the 5 names. Can anyone help me out?
thanks
try this:
truewill append data to your file.