Given this code snippet:
String[] fileList = { "/file1.txt", "/subdir/file2.txt", "/file3.txt" }; for (String file : fileList) { try {/*from w w w.java 2 s .com*/ new File(file).mkdirs(); } catch (Exception e) { System.out.println("file creation failed"); System.exit(-1); } }
Assume that the underlying file system has the necessary permissions to create files, and that the program executed successfully without printing the message "file creation failed."
In the answers, note that the term "current directory" means the directory from which you execute this program, and the term "root directory" in Windows OS means the root path of the current drive from which you execute this program.
Choose the correct option:
a)this code segment will create file1.txt and file3.txt files in the current directory, and file2.txt file in the subdir directory of the current directory b)this code segment will create file1.txt and file3.txt directories in the current directory and the file2.txt directory in the "subdir" directory in the current directory c)this code segment will create file1.txt and file3.txt files in the root directory, and a file2.txt file in the "subdir" directory in the root directory d)this code segment will create file1.txt and file3.txt directories in the root directory, and a file2.txt directory in the "subdir" directory in the root directory
d)
the mkdirs()
method creates a directory for the given name.
Since the file names have / in them, the method creates directories in the root directory (or root path for the Windows drive based on the path in which you execute this program).