Getting a codegym security exception as well...
package com.codegym.task.task13.task1319;
import java.io.*;
/*
Writing to a file from the console
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = null;
File file = new File(reader.readLine());
FileWriter fw = new FileWriter(file);
bw = new BufferedWriter(fw);
try {
if (!file.exists()) {
file.createNewFile();
}
while (true) {
String myContent = reader.readLine();
if (!myContent.equals("exit")) {
bw.write(myContent);
bw.newLine();
}
if (myContent.equals("exit")) {
bw.write("exit");
break;
}
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
finally {
try {
reader.close();
bw.close();
} catch (Exception ex) {
System.out.println("Error in closing the BufferedWriter" + ex);
}
}
}
}