Whenever I check the file, all of the input is sent on a new line, including "exit". I don't know what more to do.
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) {
// write your code here
try {
// This code writes data to a file
BufferedReader reader2 = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\xanav\\OneDrive\\Desktop\\Text\\output.txt"));
for(;;){
String text = reader2.readLine();
if(!(text.equals("exit"))){
writer.write(text + "\n"); // The + \n is required so that the strings get sent to the file on separate lines
}
else{
writer.write(text + "\n"); // This is so that "exit" also gets printed.
break;
}
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}