Как при чтении, так и при записи отсутствует:
} finally {
writer.close();
}
Как:
public String readTextFile(String fileName) {
String returnValue = "";
FileReader file;
String line = "";
try {
file = new FileReader(fileName);
BufferedReader reader = new BufferedReader(file);
try {
while ((line = reader.readLine()) != null) {
returnValue += line + "\n";
}
} finally {
reader.close();
}
} catch (FileNotFoundException e) {
throw new RuntimeException("File not found");
} catch (IOException e) {
throw new RuntimeException("IO Error occured");
}
return returnValue;
}
public void writeTextFile(String fileName, String s) {
FileWriter output;
try {
output = new FileWriter(fileName);
BufferedWriter writer = new BufferedWriter(output);
writer.write(s);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}