In this lab, you will learn to use the modern Java NIO (New Input/Output) API for file operations. You’ll implement utility methods for common file operations using the java.nio.file package.
Prerequisites
Java Development Kit (JDK) 11 or later
Your preferred Java IDE
Git for version control
Getting Started
If your instructor is using GitHub classroom, you will need to accept the assignment using the link below, clone the template repository, and import it as a project into your IDE.
publicclassFileUtils {
/**
* Creates a new file and returns success/failure message.
*/publicstatic String createFile(String fileName) throws IOException {
}
/**
* Creates a new directory and returns success/failure message
*/publicstatic String createDirectory(String dirName) throws IOException {
}
/**
* Creates nested directories and returns success/failure message
*/publicstatic String createDirectories(String path) throws IOException {
}
/**
* Copies a file to target location and returns success/failure message
*/publicstatic String copyFile(String source, String target) throws IOException {
}
/**
* Moves a file to target location and returns success/failure message
*/publicstatic String moveFile(String source, String target) throws IOException {
}
/**
* Deletes a file if it exists and returns success/failure message
*/publicstatic String deleteIfExists(String pathStr) throws IOException {
}
}
Task 2: Word Counter
Implement a method that downloads a file by it’s URL and count the number of words in it. Complete the implementation at src/main/java/cpit305/fcit/kau/edu/sa/WordCounter.java :
Implement a student record serializer in src/main/java/cpit305/fcit/kau/edu/sa/StudentSerializer.java for the Student class. Note that the Student class implements the Serializable interface. Use ObjectOutputStream with FileOutputStream to serialize the object and store it in a file. Then , use ObjectInputStream with FileInputStream to deserialize the content of the raw bytes into the Student object.
If your instructor is using GitHub classroom, then you should click on your class submission link,
link your GitHub username to your name if you have not already done so, accept the assignment, clone the
repository into your local
development environment, and push the code to the remote repository on GitHub. Please make sure that your
written
answers are included in either a README (Markdown) file or a PDF file.
Lab dues dates are listed on GitHub classroom unless otherwise
noted.
If your instructor is using GitHub classroom, your submission will be
auto-graded
by running the included unit tests as well as manually graded for correctness, style, and quality.
How to submit your lab to GitHub Classroom
The video below demonstrates how to submit your work to GitHub classroom