Hey Azndaddy,
I wrote you a quick example class showing how I would do it.
Hopefully you can use this to expand on your own work.
The program reads in a txt file, processes it line by line and after each line asks you if you want to delete it or not. If you press enter it will proceed to the next line. If you type 'delete' it will delete the current line.
The output is saved to a new file.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
public class deletelineClass {
public static void main(String[] args) throws Exception {
// Creates file to write to
Writer output = null;
output = new BufferedWriter(new FileWriter("output_path/output.txt"));
String newline = System.getProperty("line.separator");
// Read in a file & process line by line
FileInputStream in = new FileInputStream("file_path/file.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
System.out.println(strLine);
// Open up standard input from command
BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
String command = null;
System.out.println("Delete line?");
try {
command = br2.readLine();
if (command.equals("delete")){
System.out.println("Line Deleted.");
System.out.println("");
}else{
// Write non deleted lines to file
output.write(strLine);
output.write(newline);
}
} catch (IOException ioe) {
System.out.println("IO error reading command line input");
System.exit(1);
}
}
output.close();
System.out.println("End of file. DonCash is the man.");
}
}
