• Home
  • Textbooks
  • C# Programming: From Problem Analysis to Program Design
  • Working with Files

C# Programming: From Problem Analysis to Program Design

Barbara Doyle

Chapter 13

Working with Files - all with Video Answers

Educators


Chapter Questions

00:55

Problem 1

All of the following are exception classes that are thrown in conjunction
with files, except:
a. DirectoryNotFoundException
b. EndOfStreamException
c. InvalidDataFileException
d. FileNotFoundException
e. IOException

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:14

Problem 2

One difference between the DirectoryInfo class and the Directory
class is:
a. Methods of the Directory class allow you to move directories
and files; DirectoryInfo does not.
b. The DirectoryInfo class also has public properties.
c. The DirectoryInfo class is a static class.
d. The Directory class cannot be used with binary files;
DirectoryInfo can.
e. The DirectoryInfo class only has methods.

Foster Wisusik
Foster Wisusik
Numerade Educator

Problem 3

To avoid an IOException exception with files, you can either use a
try. . .catch block or make sure there is a file before attempting to read
characters from it. This can be done by:
a. calling the File.Exists( ) method
b. using a loop to cycle through the file structure
c. throwing an exception
d. including statements in a finally block
e. placing a test loop in the Main( ) method

Check back soon!
01:35

Problem 4

Which class allows you to use the Read( ) and ReadLine( ) methods
to retrieve data from a text file?
a. TextReader
b. FileReader
c. BinaryReader
d. StreamReader
e. File

Foster Wisusik
Foster Wisusik
Numerade Educator
01:35

Problem 5

Which class allows you to use the Write( ) and WriteLine( )
methods to write data to a text file?
a. TextWriter
b. FileWriter
c. BinaryWriter
d. StreamWriter
e. File

Foster Wisusik
Foster Wisusik
Numerade Educator

Problem 6

When you are finished processing a text file, you should:
a. call the Finished( ) method
b. call the Close( ) method
c. throw an exception
d. erase the file
e. reset the file

Check back soon!

Problem 7

The File class:
a. has only instance members, so to call one of its methods you must
have an object
b. has only instance members, so to call one of its methods you must
use the class name
c. has only static members, so to call one of its methods you must have
an object
d. has only static members, so to call one of its methods you must use
the class name
e. has only static members, so to call one of its methods you must use
an instance member

Check back soon!

Problem 8

To which namespace does the File class belong?
a. Object
b. System.FileSystem
c. System.Object
d. Object.IO
e. System.IO

Check back soon!
01:42

Problem 9

The members of the _______________ class allow you to create, move,
copy, and delete files.
a. File
b. FileInfo
c. Directory
d. DirectoryInfo
e. File and FileInfo

Foster Wisusik
Foster Wisusik
Numerade Educator
01:55

Problem 10

To append data onto the end of a text file:
a. use the AppendStream class
b. add the Append argument to the constructor for the FileStream
class
c. add the Append argument to the constructor for the StreamWriter
class
d. add true as the second argument (Append) to the StreamWriter
class
e. open the file in an append mode by adding an ‘a’ onto the end of the
identifier

Foster Wisusik
Foster Wisusik
Numerade Educator
01:19

Problem 11

Which of the following is an abstract class?
a. DirectoryInfo
b. Stream
c. StreamReader
d. all of the above
e. none of the above

Foster Wisusik
Foster Wisusik
Numerade Educator
01:45

Problem 12

In Visual Studio, if you do not specify the full path of a file, what directory
is used?
a. C:\
b. the project directory
c. C:\App_Data
d. bin\Debug
e. C:\WorkDirectory

Foster Wisusik
Foster Wisusik
Numerade Educator
01:45

Problem 13

Using the verbatim string, you could write the full path of
C:\CSharpProjects\ Ch13\WorkDirectory as:
a. @"C:\CSharpProjects\Ch13\WorkDirectory"@
b. @"C:\\CSharpProjects\\Ch13\\WorkDirectory"
c. @"C:\CSharpProjects\Ch13\WorkDirectory"
d. "@C:\CSharpProjects\Ch13\WorkDirectory"
e. none of the above

Foster Wisusik
Foster Wisusik
Numerade Educator
00:49

Problem 14

What method in the StreamReader class retrieves a full line of
text-up until the newline character is encountered?
a. Flush( )
b. ReadBlock( )
c. Retrieve( )
d. ReadLine( )
e. Peek( )

Ernest Castorena
Ernest Castorena
Numerade Educator
01:35

Problem 15

To make a duplicate copy of a file, you could use a static method in the
class:
a. File
b. StreamWriter
c. Stream
d. TextWriter
e. BinaryWriter

Foster Wisusik
Foster Wisusik
Numerade Educator
01:19

Problem 16

Streams can be used in C# for writing data to:
a. text files
b. networks
c. memory
d. binary files
e. all of the above

Foster Wisusik
Foster Wisusik
Numerade Educator
01:19

Problem 17

StreamReader is a direct descendent of:
a. MarshalByRefObject
b. Object
c. File
d. TextReader
e. IO

Foster Wisusik
Foster Wisusik
Numerade Educator
01:07

Problem 18

Which of the following would store an integer in a binary file?
a. Write7BitEncodedInt( )
b. WriteInt( )
c. WriteLine( )
d. StoreInt( )
e. none of the above

James Chok
James Chok
Numerade Educator
00:59

Problem 19

Which of the following methods could be used to retrieve a decimal
value from a binary file?
a. ReadDec( )
b. ReadDecimal( )
c. ReadNumber( )
d. ReadDoubleValue( )
e. ReadDecimalValue( )

Ernest Castorena
Ernest Castorena
Numerade Educator
00:49

Problem 20

All of the following methods of the BinaryReader class could be
used to retrieve data, except:
a. ReadChar( )
b. Read( )
c. ReadChars( )
d. ReadInt( )
e. ReadString( )

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 21

Write a file declaration for a file that holds text characters and can be
stored in C:\CSharpProjects\WorkDirectory. The file will be used to
store data.

Check back soon!

Problem 22

For the file declared in Exercise 21, write a method that stores the numbers 10 through 49 in the text file.

Check back soon!

Problem 23

For the file created in Exercise 22, write a method that retrieves the
values from the text file. Display 10 characters per line on the console
output screen.

Check back soon!
04:47

Problem 24

. Revise the solutions for Exercises 22 and 23 to include a try block and
at least two appropriate catch clauses inside the method.

Foster Wisusik
Foster Wisusik
Numerade Educator
03:45

Problem 25

Describe the differences between retrieving data from a text file versus
retrieving it from a binary file.

Foster Wisusik
Foster Wisusik
Numerade Educator