Deck 10: File IO

Full screen (f)
exit full mode
Question
The output stream connected to the computer screen is:

A)System.exit
B)System.quit
C)System.in
D)System.out
Use Space or
up arrow
down arrow
to flip the card.
Question
When the method readLine)tries to read beyond the end of a file,it returns the value of:

A)1
B)-1
C)null
D)none of the above
Question
The method __________ from the File class forces a physical write to the file of any data that is buffered.

A)close)
B)flush)
C)writeUTF)
D)writeObject)
Question
All of the following are methods of the File class except:

A)exists)
B)delete)
C)getDirectory)
D)getName)
Question
The class ObjectOutputStream contains all of the following methods except:

A)writeInt)
B)writeChar)
C)writeDouble)
D)println)
Question
A stream is an object that allows for the flow of data between your program and some I/O device or some file.
Question
In Java,when you open a text file you should account for a possible:

A)FileNotFoundException
B)FileFullException
C)FileNotReadyException
D)all of the above
Question
The class ObjectInputStream contains all of the following methods except:

A)readLine)
B)readChar)
C)readObject)
D)readInt)
Question
A __________ path name gives the path to a file,starting with the directory that the program is in.

A)relative
B)descendant
C)full
D)complete
Question
The FileNotFoundException is a descendant of the class IOException.
Question
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.
Question
An ____________ allows data to flow from your program.

A)input stream
B)output stream
C)file name
D)all of the above
Question
The method _________ reads a single character from an input stream.

A)readLine)
B)skip)
C)read)
D)close)
Question
There are two common classes used for reading from a text file.They are:

A)PrintWriter and BufferedReader
B)FileInputStream and Scanner
C)BufferedReader and Scanner
D)None of the above
Question
Files whose contents must be handled as sequences of binary digits are called:

A)text files
B)ASCII files
C)binary files
D)output files
Question
The read)method of the class RandomAccessFile returns the type:

A)byte
B)int
C)char
D)double
Question
An ___________ allows data to flow into your program.

A)input stream
B)output stream
C)file name
D)all of the above
Question
All of the following are methods of the Scanner class except:

A)nextFloat)
B)next)
C)useDelimiter)
D)readLine)
Question
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:

A)nextToken
B)hasNext
C)getNext
D)testNext
Question
The stream that is automatically available to your Java code is:

A)System.out
B)System.in
C)System.err
D)all of the above
Question
The File class contains methods that allow you to check various properties of a file.
Question
Write a Java method that returns a String representing a file name entered by the user.Use the BufferedReader class to obtain input.
Question
Only the classes provided for file output contain a method named close.
Question
Create try and catch block that opens a file named statistics.txt for output.Writes the integers 24,55,and 76 to the file,and then closes the file.
Question
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.
Question
The preferred stream classes for processing binary files are ObjectInputStream and ObjectOutputStream.
Question
Write a Java statement to create and open an output stream to a file named autos.txt.
Question
Using BufferedReader to read integers from a file requires the String input to be parsed to an integer type.
Question
Binary files can be handled more efficiently than text files.
Question
Binary files store data in the same format that is used by any common text editor.
Question
When your program is finished writing to a file,it should close the stream connected to that file.
Question
Write a Java statement that creates an output stream to append data to a file named autos.txt.
Question
Write a Java statement to create an input stream to a file named autos.txt.Use the BufferedReader class.
Question
Use the output stream to the file autos.txt created above in number 2 to write the line "Mercedes" to the file.
Question
A full path name gives a complete path name,starting from the directory the program is in.
Question
Write a Java statement that creates an output stream to a binary file named statistics.dat.
Question
Explain the differences between a text file,an ASCII file and a binary file.
Question
Explain what happens when an output file is opened in Java.
Question
Write a complete Java program using a BufferedReader object that opens a file named autos.txt and displays each line to the screen.
Question
What happens when the method close is invoked on a stream?
Question
Write a complete Java program using a Scanner object that opens a file named autos.txt and displays each line to the screen.
Question
Write a Java statement to create an input stream to the binary file statistics.dat.
Question
Write a Java statement to create an input stream to a file named "statistics.dat".
Question
Write a complete Java program that opens a binary file containing integers and displays the contents to the screen.
Question
Write a Java statement that creates a stream that provides read/write access to the file named autos.txt.
Question
Use the output stream created in number 11 above to write the String BBC to the file named statistics.dat.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: File IO
1
The output stream connected to the computer screen is:

A)System.exit
B)System.quit
C)System.in
D)System.out
D
2
When the method readLine)tries to read beyond the end of a file,it returns the value of:

A)1
B)-1
C)null
D)none of the above
C
3
The method __________ from the File class forces a physical write to the file of any data that is buffered.

A)close)
B)flush)
C)writeUTF)
D)writeObject)
B
4
All of the following are methods of the File class except:

A)exists)
B)delete)
C)getDirectory)
D)getName)
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
5
The class ObjectOutputStream contains all of the following methods except:

A)writeInt)
B)writeChar)
C)writeDouble)
D)println)
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
6
A stream is an object that allows for the flow of data between your program and some I/O device or some file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
7
In Java,when you open a text file you should account for a possible:

A)FileNotFoundException
B)FileFullException
C)FileNotReadyException
D)all of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
The class ObjectInputStream contains all of the following methods except:

A)readLine)
B)readChar)
C)readObject)
D)readInt)
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
9
A __________ path name gives the path to a file,starting with the directory that the program is in.

A)relative
B)descendant
C)full
D)complete
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
10
The FileNotFoundException is a descendant of the class IOException.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
11
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
12
An ____________ allows data to flow from your program.

A)input stream
B)output stream
C)file name
D)all of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
13
The method _________ reads a single character from an input stream.

A)readLine)
B)skip)
C)read)
D)close)
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
There are two common classes used for reading from a text file.They are:

A)PrintWriter and BufferedReader
B)FileInputStream and Scanner
C)BufferedReader and Scanner
D)None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
15
Files whose contents must be handled as sequences of binary digits are called:

A)text files
B)ASCII files
C)binary files
D)output files
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
16
The read)method of the class RandomAccessFile returns the type:

A)byte
B)int
C)char
D)double
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
17
An ___________ allows data to flow into your program.

A)input stream
B)output stream
C)file name
D)all of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
18
All of the following are methods of the Scanner class except:

A)nextFloat)
B)next)
C)useDelimiter)
D)readLine)
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
19
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:

A)nextToken
B)hasNext
C)getNext
D)testNext
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
20
The stream that is automatically available to your Java code is:

A)System.out
B)System.in
C)System.err
D)all of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
21
The File class contains methods that allow you to check various properties of a file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
Write a Java method that returns a String representing a file name entered by the user.Use the BufferedReader class to obtain input.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
23
Only the classes provided for file output contain a method named close.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
24
Create try and catch block that opens a file named statistics.txt for output.Writes the integers 24,55,and 76 to the file,and then closes the file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
25
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
The preferred stream classes for processing binary files are ObjectInputStream and ObjectOutputStream.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
Write a Java statement to create and open an output stream to a file named autos.txt.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
Using BufferedReader to read integers from a file requires the String input to be parsed to an integer type.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
Binary files can be handled more efficiently than text files.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
Binary files store data in the same format that is used by any common text editor.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
When your program is finished writing to a file,it should close the stream connected to that file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
32
Write a Java statement that creates an output stream to append data to a file named autos.txt.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
Write a Java statement to create an input stream to a file named autos.txt.Use the BufferedReader class.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
34
Use the output stream to the file autos.txt created above in number 2 to write the line "Mercedes" to the file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
35
A full path name gives a complete path name,starting from the directory the program is in.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
36
Write a Java statement that creates an output stream to a binary file named statistics.dat.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
Explain the differences between a text file,an ASCII file and a binary file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
38
Explain what happens when an output file is opened in Java.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
Write a complete Java program using a BufferedReader object that opens a file named autos.txt and displays each line to the screen.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
40
What happens when the method close is invoked on a stream?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
Write a complete Java program using a Scanner object that opens a file named autos.txt and displays each line to the screen.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
Write a Java statement to create an input stream to the binary file statistics.dat.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
43
Write a Java statement to create an input stream to a file named "statistics.dat".
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
44
Write a complete Java program that opens a binary file containing integers and displays the contents to the screen.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
Write a Java statement that creates a stream that provides read/write access to the file named autos.txt.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
46
Use the output stream created in number 11 above to write the String BBC to the file named statistics.dat.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 46 flashcards in this deck.