Lab 14: Text Editor File I/O¶
Welcome to the Nanovimacs project! We are building a next-generation, terminal-based editor. Our editor will replace nano, vi, emacs, and others. (Just kidding.)
The goal of this lab is to practice file I/O by adding load/save functionality to the following provided files:
- Document.java
Represents a plain text file as anArrayListof strings (i.e., the lines of the file). - Editor.java
An application that provides a command-line interface to theDocumentclass.
You can run the Editor application from the terminal and/or VS Code.
You can also run the provided tests:
Refer to the Java API documentation as needed:
Part 1: Document¶
Download the files above and complete the Document class.
The unfinished methods should conform to the Javadoc comments.
Test your completed file by running the provided JUnit tests.
Part 2: Editor¶
The current implementation of the Editor class does not include code for handling exceptions related to file I/O.
If you attempt to open a non-existent file, or to write a file to a location where do not have permission, the application will crash.
Modify Editor by removing all throws declarations and adding try/catch blocks to saveFile() and loadFile().
If an exception occurs, these methods should print a helpful error message and then allow execution to proceed normally.
Optional Work¶
Most text editors allow you to save the current document without having to re-enter the filename.
Modify the Editor class to provide this functionality.
If the file is already associated with a filename (because of an earlier save or load), then the "s" command should now save the current version without prompting for a filename.
You should also add a save-as command to allow specifying a filename even if one already exists.
Use "w" to represent save-as.
Make sure to update the help message to conform to the new functionality.
Submission¶
Submit Document.java and Editor.java to Gradescope in a lab14 packaged folder.
Do not submit the test files or delete them in the submission before final upload.
Points will be allocated as follows:
| Criterion | Points | Details |
|---|---|---|
| Compile | 0 pts | Success Required |
| CompileOfficialTests | 0 pts | Success Required |
| Style | 0 pts | Success Required |
| OfficialTests | 10 pts | Partial Credit Possible |