Writing to a file from the console

  • 16
  • Locked
Now you need to write something to a file. You need to first read the file name from the console, then read lines entered by the user until the user enters "exit". Finally, write all the entered lines to the file, each on a new line.
You can't complete this task, because you're not signed in.
Comments (13)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
22 January, 17:55
For those with condition 5 error; I forgot I had hardcoded my file path. This could be one of the reasons this condition fails (I had it all running ages ago...:)
Kent Hervey Level 15, United States
31 December 2020, 23:15
Have not started coding yet. the summary into says to write to the console, but the requirements say don't I will start with the latter
LennyMan Level 25, Lucca, Italy
27 December 2020, 14:07
It was hard, i definetely needed to check the Help section, but man, finally we start to code something real! 😋
Roman Hryhorchuk Level 17, Cracow, Poland
19 November 2020, 21:33
Admin, I believe that there might be some issues with the tests. I have passed this exercise but I was not able to see the provided in console text in the file.
MoJo Level 22, Cairns, Australia
15 October 2020, 09:50
tip: by adding + "\n" to any string you are adding a line break to it.
Switch/Cypher Level 25, Bexleyheath, United Kingdom
23 September 2020, 13:06
Yeah this is hard.
Petros Level 23, Columbia, United States
4 August 2020, 17:50
Brutal. Had to go straight to help to figure this one out.
Devonte A Level 17, Rubery, United Kingdom
2 August 2020, 13:42
A tip that helped me to finally progress past the 5th requirement is to make the filename read from the buffered reader hence the main method will throw an IOException.
Lucas Hoage Level 14, Savannah, United States
10 June 2020, 21:21
This isn't difficult to build as it is difficult to understand the last expectation. It really should mention that a new line must be printed after you write exit. You also don't need to read a file name from console. You can create a new File object and assign it a file address and pass that along the chain. This isn't checked. Example: File file = new File("home/lucas/Desktop/g/text"); Then pass file through FileOutPutStream or FileWriter parameters when passing arguments into the BufferedWriter object creation.
MICHAEL DUNLAP Level 19, Bellevue, United States
22 August 2019, 05:17
Finally got it to pass. My condition for checking for "exit" had to go at the very bottom of the while loop to pass the 4th condition. Also, the 5th requirement is tricky. I wasn't passing it until I commented out the line that adds the name of the file as a line in the file. The requirement does state that ALL entered lines must be in the file-- would this not include the entered name of the file? Apparently not.