AFAIK, No OS supports deleting part of a file (except the end)
You can't delete a file you have open so you have to be sure you closed it everywhere, but you can create a temporary file and rename it as the original. (No need to copy it back)
Here is how I might write it
public static void removeLine(String filename, String line) {
File from = new File(filename);
File tmp = new File(filename + ".tmp");
PrintWriter pw = null;
BufferedReader br = null;
try {
pw = new PrintWriter(tmp);
br = new BufferedReader(new FileReader(from));
boolean found = false;
for (String line2; (line2 = br.readLine()) != null; )
if (line2.equals(line))
found = true;
else
pw.println(line2);
pw.close();
br.close();
if (found) {
from.delete();
tmp.renameTo(from);
} else {
tmp.delete();
}
} catch (IOException e) {
// log error.
try { if (br != null) br.close(); } catch (IOException ignored) { }
if (pw != null) pw.close();
}
}