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 (19)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 22 , San Diego, United States
5 March, 03:58
HELP has good discussions already going -- jump into one right HERE: https://codegym.cc/help/5068
Vadim “迪姆哥”
Level 26 , Kazakhstan
28 November 2022, 18:25
I think that that line: "Program must absolutely write all of the entered lines (includes "exit") to the file, each on a new line" Isn't clear about requirenment, which is: user must store all lines in buffer, then after it receive "exit" line in console, write all contents stored in buffer with "exit" line to the file.
Hiyo Full Stack Developer
3 February, 02:44
It's pretty clear to me. Read each line from console and write to file. It's a loop, if the current line happens to be "exit", write it to file and break out of the loop. That's all. Maybe you used a different method, I'm not sure but this was what I understood from the requirement.
Justin Smith
Level 39 , Greenfield, USA, United States
2 August 2021, 18:20
This looked scary, but I got it on my first try! One of the really helpful things about IDEA is that, when you have your BufferedWriter object, you can then type the name of the object plus a period and it will show you all the methods you might want to use. For this task, that helped a lot with figuring out how to write the data to the file and tell it to go to the next line of the file.
Level 22 , San Diego, United States
5 March, 03:42
THX I am using the CG IDE way too much
22 January 2021, 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 Software Engineer/Consult at Zeal IT ConsultantsExpert
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
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 Grygorczuk
Level 19 , 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.
Level 22 , Cairns, Australia
15 October 2020, 09:50
tip: by adding + "\n" to any string you are adding a line break to it.
Level 25 , Bexleyheath, United Kingdom
23 September 2020, 13:06
Yeah this is hard.
Level 23 , Columbia, United States
4 August 2020, 17:50
Brutal. Had to go straight to help to figure this one out.
Level 22 , San Diego, United States
5 March, 03:47
I look at so much other code to kick-off ideas. It's already written and in the wild to use and even improve it. Look at StackO / Reddit / Chat GPT / Googs / YouTube / GitHub / Codegym Articles / CG Chat all that --- so many cool and different implementations to ponder over ...