Exam 10: File IO

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

An ____________ allows data to flow from your program.

Free
(Multiple Choice)
4.8/5
(39)
Correct Answer:
Verified

B

Explain the differences between a text file,an ASCII file and a binary file.

Free
(Essay)
4.9/5
(45)
Correct Answer:
Verified

Text files are files that appear to contain sequences of characters when viewed in a text editor or read by a program.Text files are sometimes also called ASCII files because they contain data encoded using a scheme known as ASCII coding.Files whose contents must be handled as sequences of binary digits are called binary files.

Write a complete Java program using a BufferedReader object that opens a file named autos.txt and displays each line to the screen.

Free
(Essay)
4.7/5
(39)
Correct Answer:
Verified

import java.io.BufferedReader; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException; public class TextDemo { public static void main(String args[]) { BufferedReader inputStream = null; try { inputStream = new BufferedReader(new FileReader("autos.txt")); String line = inputStream.readLine(); while(line != null) { System.out.println(line); line = inputStream.readLine(); } inputStream.close(); } catch(FileNotFoundException e) { System.out.println("Error opening files."); } catch(IOException e) { System.out.println("Error reading from file."); } } }

Using BufferedReader to read integers from a file requires the String input to be parsed to an integer type.

(True/False)
4.8/5
(38)

Write a complete Java program using a Scanner object that opens a file named autos.txt and displays each line to the screen.

(Essay)
4.7/5
(35)

Write a complete Java program that opens a binary file containing integers and displays the contents to the screen.

(Essay)
4.8/5
(37)

Explain what happens when an output file is opened in Java.

(Essay)
4.9/5
(38)

The methods of the scanner class do not behave the same when reading from a text file as they do when used to read from the keyboard.

(True/False)
4.9/5
(29)

The class ObjectOutputStream contains all of the following methods except:

(Multiple Choice)
5.0/5
(30)

What happens when the method close is invoked on a stream?

(Essay)
4.9/5
(32)

The method _________ reads a single character from an input stream.

(Multiple Choice)
4.9/5
(37)

The class ObjectInputStream contains all of the following methods except:

(Multiple Choice)
4.9/5
(40)

The preferred stream classes for processing binary files are ObjectInputStream and ObjectOutputStream.

(True/False)
4.8/5
(38)

Write a Java statement that creates a stream that provides read/write access to the file named autos.txt.

(Essay)
4.9/5
(31)

Use the output stream to the file autos.txt created above in number 2 to write the line "Mercedes" to the file.

(Short Answer)
4.7/5
(42)

Every input file and every output file used by your program has only one name which is the same name used by the operating system.

(True/False)
4.8/5
(39)

The scanner class has a series of methods that checks to see if there is any more well-formed input of the appropriate type.These methods are called __________ methods:

(Multiple Choice)
4.7/5
(25)

The File class contains methods that allow you to check various properties of a file.

(True/False)
4.8/5
(47)

The read()method of the class RandomAccessFile returns the type:

(Multiple Choice)
4.9/5
(45)

Use the output stream created in number 11 above to write the String BBC to the file named statistics.dat.

(Short Answer)
4.7/5
(38)
Showing 1 - 20 of 46
close modal

Filters

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