Which code options when inserted at /* INSERT CODE HERE */ will copy the specified file from the specified source to the destination?.
public static void copyFile (String src, String dest) throws IOException{ /* INSERT CODE HERE */ java.nio.file.Files.copy(source, destination); }
a Path source = Paths.get(src); Path destination = Paths.get(dest); b FileInputStream source = new FileInputStream(new File(src)); Path destination = Paths.get(dest); c Path source = Paths.get(src); BufferedOutputStream destination = new BufferedOutputStream( new FileOutputStream(dest)); d FileInputStream source = new FileInputStream(new File(src)); FileOutputStream destination = new FileOutputStream(new File(dest));
a, b, c
The overloaded copy()
method in class Files can copy a source to a destination in the following formats:
Therefore, options (a), (b), and (c) are correct.
FileInputStream extends InputStream, FileOutputStream extends OutputStream, and BufferedOutputStream extends OutputStream.
So their objects can be passed to Files.copy()
.
Option (d) is incorrect because method copy()
in class Files doesn't copy InputStream to OutputStream.