The output is correct, it writes content to the file, every String is on a new line, why doesn't the program validate.
package com.codegym.task.task13.task1319;
import javax.imageio.IIOException;
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));
String fileName = reader.readLine();
BufferedWriter bw = null;
try {
File file = new File(fileName);
FileWriter fw = new FileWriter(file);
bw = new BufferedWriter(fw);
if(!file.exists()){
file.createNewFile();
}
while(true){
String a = reader.readLine();
if(!a.equals("exit"))
bw.write(a);
bw.newLine();
if(a.equals("exit")){
break;
}
}
}
catch (Exception e){
}
bw.close();
}
}