Question: The Java Code below needs to have comments added. Once you have correctly run and tested the program, comment in the source code where there
The Java Code below needs to have comments added. Once you have correctly run and tested the program, comment in the source code where there is a Comment Here statement. Also respond to the 3 challenge questions below. Be sure your response includes proper rationale to support your reasoning. Copy and paste completed code and type answers to challenge questions.
Code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFileContent {
public static void main(String[] args) {
/* Comment Here */
File sourceFile = new File("file1.txt");
/* Comment Here */
File destFile = new File("file2.txt");
/* Comment Here */
if (!destFile.exists()) {
try {
destFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
InputStream input = null;
OutputStream output = null;
try {
/* Comment Here */
input = new FileInputStream(sourceFile);
/* Comment Here */
output = new FileOutputStream(destFile);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
if (null != input) {
input.close();
}
if (null != output) {
output.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Challenge Questions:
1. The services and functions provided by an operating system can be divided into two main categories. Briefly describe the two categories and discuss how they differ.
2. What are the five major activities of an operating system with regard to file management?
3.What is the main advantage for an operating-system designer of using a virtual-machine architecture? What is the main advantage for a user?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
