How many lines of the following program contain compilation errors?
public class Main { public static void organize(Path folder, Path file) throws IOException { Path p = folder.resolve(file); BasicFileAttributeView vw = Files.getFileAttributeView(p, BasicFileAttributes.class); if(vw.creationTime().toMillis()<System.currentTimeMillis()) { vw.setTimes(FileTime.fromMillis(System.currentTimeMillis()), null,null); /*from w w w .java 2s .c o m*/ } } public static void main(String[] audio) throws Exception { Main.organize(Paths.get("/", "pub"),new File("/data").toPath()); } }
C.
The Files.getFileAttributeView()
method requires a reference to a subclass of FileAttributeView, such as BasicFileAttributeView.class.
The parameter must also be compatible with the reference assignment to vw.
For these two reasons, this line of code does not compile.
Next, BasicFileAttributeView does not contain a creationTime()
method, so vw.
creationTime()
results in a compilation error.
Since these are the only two lines that contain compilation errors, Option C is the correct answer.