Create a text file (with an editor such as Microsoft NotePad) named TwoYearsBeforeTheMast.txt which contains this text:
Question:
Create a text file (with an editor such as Microsoft NotePad) named TwoYearsBeforeTheMast.txt which contains this text:
Six days shalt thou labor and do all thou art able, and on the seventh—holystone the decks and scrape the cable.
Implement a program that creates a directory named RichardHenryDana that resides as a subdirectory in the current directory. The program moves the text file from the current directory to the new subdirectory.
In your program, instantiate one Path object for the TwoYearsBeforeTheMast.txt file and instantiate another Path object for the RichardHenryDana subdirectory. Then use those two paths with the resolve method to create a destination Path object for where the file is supposed to go. Next, check to see if the subdirectory already exists, and if it does not, create the new subdirectory. Then attempt to move the file to the subdirectory. Use a try-catch mechanism to handle failure.
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean