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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: