Question
JAVA PROJECT (PLEASE SHOW SOLUTION) Create a NetBeans project for this activity. Consider the following code. Our goal is to be able to print all
JAVA PROJECT (PLEASE SHOW SOLUTION)
Create a NetBeans project for this activity.
Consider the following code. Our goal is to be able to print all the files in the given directory by completing the codes. Choose or create a folder with files in it. Add the directory in the
import java.io.___________;
public class FileIO {
public static void main(String args[]) {
File dir = new File(
____________ items = dir.____________;
for (File item : items) {
System.out.println(item._____________);
}
}
}
Test Stem / Question | Choices |
5: In order to use the class and methods of File. What should we import? | A: File |
B: FileClass | |
C: Files | |
D: Streams | |
6: In order to list all the files and directories inside the File instance, what method should you use in B? | A: listFiles() |
B: getFiles() | |
C: getAllFiles() | |
D: getDirectories() | |
7: What is the return type of that method? | A: An array of File object |
B: Collection of File object | |
C: An array of Object object | |
D: An Array of string directories | |
8: In D, we would like to get the absolute path of the Files. What method should you use? | A: getAbsolutePath() |
B: getAbsoluteFilePath() | |
C: toAbsolutePath() | |
D: toAbsoluteFilePath() | |
9: Now that we have completed the code, try to run it. What is the result? | A: It listed all the path inside the directory. |
B: Compiler error since we did not throw or catch an exception. | |
C: Compiler error since we did not use the try catch statements | |
D: Nothing | |
10: Going back to the code, we would like to check if there is a file present. What method should you use? | A: exists() |
B: isPresent() | |
C: isAvailable() | |
D: isValidDirectory() |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started