Exam 7: Inputoutput and Exception Handling

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. Public void String readFile() throws IOException { File inputFile = new File(. . .); Scanner in = new Scanner(inputFile); Try { While (in.hasNext()) { ) . . } } Finally { ___________________ } }

(Multiple Choice)
4.8/5
(33)

Insert the missing code in the following code fragment. This fragment is intended to read an input file. Public static void main(String[] args) __________________ { String inputFileName = "dataIn.txt"; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); ) . . }

(Multiple Choice)
4.8/5
(48)

Which String class method will remove spaces from the beginning and the end of a string?

(Multiple Choice)
4.9/5
(33)

Which of the following statements about checked and unchecked exceptions is true?

(Multiple Choice)
4.9/5
(45)

An example of a fatal error that rarely occurs and is beyond your control is the ____.

(Multiple Choice)
4.8/5
(34)

Consider the following code snippet. Scanner inputFile = new Scanner("dataIn.txt"); Which of the following statements is correct?

(Multiple Choice)
4.8/5
(39)

Consider the following code snippet. PrintWriter outFile = new PrintWriter("dataOut.txt"); Which of the following statements about the PrintWriter object is correct?

(Multiple Choice)
5.0/5
(32)

Which of the following objects should be used for reading from a text file?

(Multiple Choice)
4.7/5
(33)

Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt that resides in a folder named payroll on the C: drive of a Windows system. Public static void main(String[] args) throws FileNotFoundException { File inputFile = ________; Scanner in = new Scanner(inputFile); ) . . }

(Multiple Choice)
4.8/5
(36)

Consider the following code snippet. PrintWriter outputFile = new PrintWriter("payrollReport.txt"); Which of the following statements about the PrintWriter object is correct?

(Multiple Choice)
4.9/5
(36)

Under which condition will the PrintWriter constructor generate a FileNotFoundException?

(Multiple Choice)
4.8/5
(35)

Which statement about handling exceptions is true?

(Multiple Choice)
4.8/5
(36)

Which of the following patterns should be used for the delimiter to read one character at a time using a Scanner object's next method?

(Multiple Choice)
4.9/5
(40)

Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. Try { String filename = . . .; Scanner in = new Scanner(new File(filename)); ) . . } ___________________ { Exception.printStackTrace(); }

(Multiple Choice)
4.8/5
(31)

Insert the missing code in the following code fragment. This fragment is intended to read a file and write to a file. Public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = _____________; ) . . }

(Multiple Choice)
4.8/5
(46)

Insert the missing code in the following code fragment. This fragment is intended to allow the user to select a file to be opened. JFileChooser chooser = new JFileChooser(); Scanner in = null; If (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = __________; In = new Scanner(selectedFile); ) . . }

(Multiple Choice)
4.9/5
(44)

If the current method in a program will not be able to handle an exception, what should be coded into the method?

(Multiple Choice)
4.9/5
(39)

Consider the following code snippet. Scanner inputFile = new Scanner("hoursWorked.txt"); Which of the following statements is correct?

(Multiple Choice)
4.8/5
(23)

Consider the following code snippet: Scanner in = new Scanner(. . .); While (in.hasNextLine()) { String input = in.nextLine(); System.out.println(input); } Which of the following statements about this code is correct?

(Multiple Choice)
4.7/5
(45)

Which of the following statements about using the PrintWriter object is correct?

(Multiple Choice)
4.8/5
(35)
Showing 41 - 60 of 100
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)