I used a filewriter class to write my inputs into a text file. Is there a way I can delete a line in the txt file created?
import java.util.*;
import java.io.*;
class Main {
public static void main(String args[]) {
Scanner read = new Scanner(System.in);
try{
FileWriter f = new FileWriter("output.txt", false);
for (int x = 0; x < 5; x++){
System.out.print("Enter a word: ");
f.write(x+1 + " " + read.nextLine() + '\n');
}
f.close();
}
catch(IOException e){
System.out.println(e);
}
}
}
The strings written in the file is
what if I want to remove 2 hello from the contents of the file? What should I do?