Not passing write exit to file
package com.codegym.task.task13.task1319;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.*;
/*
Writing to a file from the console
*/
public class Solution {
public static void main(String[] args) {
// write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringWriter sw =null;
BufferedWriter bw = null;
// create new string writer
sw = new StringWriter();
// create new buffered writer
bw = new BufferedWriter(sw);
String name = "";
try {
while(true){
name = reader.readLine();
if (name.equals("exit")){
break;
}
bw.write(name);
bw.newLine();
}
bw.flush();
bw.newLine();
bw.close();
}catch (Exception e){
}
}
}