1B. Your program wishes to open a file named C:\\java\\myProg\\input.txt on a Wi
ID: 3697744 • Letter: 1
Question
1B.
Your program wishes to open a file named C:javamyProginput.txt on a Windows system. Which of the following is the correct code to do this?
Select one:
a. inputFile = new File("c:javamyProginput.txt");
b. inputFile = new File.open("c:javamyProginput.txt");
c. inputFile = new File("c:\java\myProg\input.txt");
d. inputFile = new File.open("c:\java\myProg\input.txt");
2B.
Under which condition will the Scanner constructor generate a FileNotFoundException?
Select one:
a. If the input file cannot be opened due to a security error.
b. If the input file does not exist.
c. If the input file already exists, but has data in it.
d. If the input file already exists, but is empty.
3B.
Which of the following is the correct syntax for creating a File object?
Select one:
a. File inFile = File("input.txt")
b. File inFile = new File("input.txt")
c. File inFile = File.open("input.txt")
d. File inFile = new File.open("input.txt")
4B.
Consider the following code snippet:
Which of the following statements about this code is correct?
Select one:
a. The file will be closed regardless of when the exception occurs.
b. The file will be closed if the PrintWriter constructor throws an exception.
c. The file will be closed if the writeData() statement throws an exception.
d. It is not possible to determine whether the file will be closed if an exception occurs.
5B.
ert the missing code in the following code fragment. This fragment is intended to read a web page.
Select one:
a. new Scanner("http://horstmann.com/index.html")
b. new Scanner(pageLocation)
c. new Scanner(new File(pageLocation))
d. new Scanner(pageLocation.openStream())
Explanation / Answer
1B).
c. inputFile = new File("c:\java\myProg\input.txt");
2B).
b. If the input file does not exist.
3B).
b. File inFile = new File("input.txt")
4B).
a. The file will be closed regardless of when the exception occurs.
Explanation: finally block executes in all cases (regardless of when the exception occurs).
5B).
d. new Scanner(pageLocation.openStream())
Explanation:
openStream()
Opens a connection to this URL and returns an InputStream for reading from that connection.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.