New question. How do I delete a line from a text file? I've tried writing all the lines EXCEPT the one I want deleted to a temporary file, then writing the lines of the temporary file into the original file, thus removing the line to be deleted. But it's not working... here's my code for that:
public static void delcountry (String inputfile) throws IOException
{
c.println ();
String line, country;
c.println ("Please enter the country you would like deleted from the file. ");
country = c.readLine ();
BufferedReader input;
PrintWriter output;
input = new BufferedReader (new FileReader (inputfile));
output = new PrintWriter (new FileWriter ("temp.txt", true));
line = input.readLine ();
while (line != null)
{
if (line != country)
{
output.println (line);
line = input.readLine ();
}
}
input.close ();
output.close ();
input = new BufferedReader (new FileReader ("temp.txt"));
output = new PrintWriter (new FileWriter (inputfile));
line = input.readLine ();
while (line != null)
{
output.println (line);
line = input.readLine ();
}
input.close ();
output.close ();
}
If you see a "c" as in c.println();, it means something like "System.out"