Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- General reminders:
- Your name and assignment within the fir st 4 lines of source code in each file.
- Include ALL files for the project to run.
- Your name and assignment should show in GUI or console when the program runs.
- Use the specified file/class names for the project. If you need more classes, that's okay.
- If you use JFileChooser: leave it opening in user.home directory! That is, with the no-arg constructor -- not JFileChooser(".") If you want to speed up your debugging, feel free to pre-load the text box with something like
- "C:\\users\\...\\mytestdata.txt"
- Please don't use any "package" statements!
- You will submit FilesAreFun.java
- It will use JFileChooser to allow the user to choose a file to copy.
- If the user selects Cancel, the program should display "Ok, if you say so." and stop using System.exit(1).
- Now use JFileChooser.showSaveDialog to allow the user to select a file to write.
- If the user cancels, the program should display "No output, eh?" and stop using a System.exit(2)
- If the file exists, you should warn the user, and allow the user to select a different file name if they want, or write over the existing file if they want.
- (Hint: use File and the .exists() boolean method)
- If the user selects an output file, you should copy the file from the input to the output , line by line. However, each input line should be preceded by a line number.
- For example, if the input file looks like:
- ***********************************************
- john
- mildred
- fred
- ralph t. iguana
- tammerlane
- Gengis
- Attila
- ***********************************************
- the output file should look like:
- ***********************************************
- 1: john
- 2: mildred
- 3: fred
- 4: ralph t. iguana
- 5: tammerlane
- 6: Gengis
- 7: Attila
- ***********************************************
- When your program completes, it should display a message like:
- "Done, successfully copied 7 lines."
- Extra credit opportunity: format the line number as four digit numbers so things line up nicely if there are more than 10 lines in the file:
- ***********************************************
- 0001: john
- 0002: mildred
- 0003: fred
- 0004: ralph t. iguana
- 0005: tammerlane
- 0006: Gengis
- 0007: Attila
- ***********************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement