I am unsure why I am not passing the verification, because when I write:
B:\Documentos\temp.txt
Line1
Line2
Line3
exit
I end up having the file as requested, I also tried changing line 32 by content = content + newline;
with identical results.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 {
// write your code here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String filepath = "";
String content = "";
String newline = "";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
try
{
filepath = br.readLine();
newline = br.readLine();
while (!newline.equals("exit")){
content = content + newline + "\n";
newline = br.readLine();
}
content = content + newline+ "\n";
File file = new File(filepath);
if (!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
bw = new BufferedWriter(fw);
bw.write(content);
} catch (Exception e){
System.out.println(e);
} finally {
bw.close();
br.close();
}
}
}