Tag Archives: path

Given: String originalPath = "data\\projects\\a-project\\..\\..\\another-project"; Path path = Paths.get(originalPath);

Given:String originalPath = “data\\projects\\a-project\\..\\..\\another-project”; Path path = Paths.get(originalPath); System.out.print(path.normalize()); What is the result? A. data\another-project B. data\projects\a-project\another-project C. data\\projects\\a-project\\..\\..\\another-project D. data\projects\a-project\..\..\another-project Correct Answer: D

Given the code fragment: (Exhibit) You want to examine whether path is a directory. Which code inserted

Given the code fragment:You want to examine whether path is a directory.Which code inserted on line 1 will accomplish this? A. BasicFileAttributes attributes = Files isDirectory (path); B. BasicFileAttributes attributes = Files, readAttributes (path, FileAttributes, class); C. BasicFileAttributes attributes =Files.getAttribute (path, ”insdirectory”); D. BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class Correct Answer: B

Given the code fragment: Path source = Paths.get("/repo/a/a.txt"); Path destination = Paths.get("/repo");

Given the code fragment:Path source = Paths.get(“/repo/a/a.txt”);Path destination = Paths.get(“/repo”);Files.move(source, destination); // line 1Files.delete (source); // line 2Assuming the source file and destination folder exist, what Is the result? A. a.txt is renamed repo. B. A java.nio.file.NoSuchFileException is thrown on line 2. C. A copy of /repo/a/a.txt is moved to the /repo directory and /repo/a/a.txt is deleted. D.… Read More »

Given: String originalPath = "data\\projects\\a-project\\..\\..\\another-project"; Path path = Paths.get(originalPath);

Given:String originalPath = “data\\projects\\a-project\\..\\..\\another-project”; Path path = Paths.get(originalPath); System.out.print(path.normalize()); What is the result? A. data\another-project B. data\projects\a-project\another-project C. data\\projects\\a-project\\..\\..\\another-project D. data\projects\a-project\..\..\another-project Correct Answer: D

Given the code fragment: Path source = Paths.get("/repo/a/a.txt"); Path destination = Paths.get("/repo");

Given the code fragment:Path source = Paths.get(“/repo/a/a.txt”);Path destination = Paths.get(“/repo”);Files.move(source, destination); // line 1Files.delete (source); // line 2Assuming the source file and destination folder exist, what Is the result? A. a.txt is renamed repo. B. A copy of /repo/a/a.txt is moved to the /repo directory and /repo/a/a.txt is deleted. C. A java.nio.file.NoSuchFileException is thrown on line 2. D.… Read More »

Given: String originalPath = "data\\projects\\a-project\\..\\..\\another-project"; Path path = Paths.get(originalPath);

Given:String originalPath = “data\\projects\\a-project\\..\\..\\another-project”; Path path = Paths.get(originalPath); System.out.print(path.normalize()); What is the result? A. data\another-project B. data\projects\a-project\another-project C. data\\projects\\a-project\\..\\..\\another-project D. data\projects\a-project\..\..\another-project Correct Answer: D

Given the code fragment: Path currentFile = Paths.get("/scratch/exam/temp.txt"); Path outputFile = Paths

Given the code fragment:Path currentFile = Paths.get(“/scratch/exam/temp.txt”);Path outputFile = Paths get(“/scratch/exam/new.txt”);Path directory = Paths.get(“/scratch/”);Files.copy(currentFile, outputFile);Files.copy(outputFile, directory);Files.delete (outputFile);The /scratch/exam/temp.txt file exists. The /scratch/exam/new.txt and /scratch/new.txt files do not exist.What is the result? A. /scratch/exam/new.txt and /scratch/new.txt are deleted. B. The program throws a FileaAlreadyExistsException. C. The program throws a NoSuchFileException. D. A copy of /scratch/exam/new.txt exists in the /scratch… Read More »