Given the code fragment:
You want to validate a path name before the read file. Before validation, all path names should be canonicalized.
Which code inserted on line n1 will accomplish this?
Given the code fragment:
You want to validate a path name before the read file. Before validation, all path names should be canonicalized.
Which code inserted on line n1 will accomplish this?
To validate a path name before reading a file and ensure the path names are canonicalized, the best approach is to use the getCanonicalPath() method. This method returns the canonical (unique and absolute) pathname string. The correct code to accomplish this involves creating a File object using the filename, obtaining the canonical path using getCanonicalPath(), and then using that path to create a FileInputStream object. Therefore, the code inserted on line n1 should follow the process outlined in option D.
answer : D A canonical pathname is both absolute and unique. That means it includes getting absolute path and no removing redundant names (normalization). ABC doesn't include both those operations. D includes it with file.getCanonicalPath();
D is correct, only has a bad sintax canonicalPath pass to new Fileins(canonicalPah) no other opcion convert filename to canonical name only this
B is best answer C and D do not compile when tested
D is correct The file object is created using the filename variable.The getCanonicalPath() method is called on the file object to get the canonical path of the file.The canonicalPath variable is then used to create a new FileInputStream object. This code will ensure that the path name is validated and canonicalized before the file is read.
D we use file.getCanonicalPath()