Practice pieces


IO

This practice piece gives you a chance to experiment with using Scanners and FileWriters.


Hints:

You just need one, main, class to do this job.

The algorithm is:

// Make a File object for a file. Just give a filename (no path) and it will appear in the directory the code runs from.
// Make a BufferedWriter/FileWriter for the file.
// Make a Scanner attached to System.in.
// Open a while-loop that reads lines from the scanner into a String variable until (!stringVar.equals("")).
// After you've read the String from the scanner, write it to the file, plus a newLine marker.
// End the while-loop.
// Close the file.

Note that you'll need to make sure the String variable is setup before the while loop, and set to something other than "".

If you need more help, here's the answers (or one option, anyhow).