FileIO Flashcards

1
Q

Which is the simpler searching algorithm to implement?

A

Linear Search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which searching algorithm needs to use a sorted list?

A

Binary Search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a text file?

A

A file consisting of multiple lines of text characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What classes are not standard in Java I/O?

A

InputFile and OutputFile classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of I/O?

A

Storing data to ‘nonvolatile‘ devices, e.g. Harddrive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two types of streams in Java?

A
  • Text streams * Binary streams
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the two directions of streams in Java?

A
  • Input * Output
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the four base-classes dealing with I/O in Java?

A
  • Reader: text-input * Writer: text-output * InputStream: byte-input * OutputStream: byte-output
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What character terminates a text file?

A

The new-line character ‘\n’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is EOF in file processing?

A

End-of-file character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the general scheme for reading/writing in Java?

A
  • Open an input/output stream * Read/write next data from/to the stream * Close the stream
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which class reads characters from a file?

A

FileReader Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the BufferedReader class do?

A

Reads a line of text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What exception might be thrown during I/O operations?

A

IOException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Try-catch blocks are used for what purpose in I/O?

A

To handle exceptions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What class is used to write characters to a file?

A

FileWriter class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the benefit of using BufferedWriter?

A

Provides efficient writing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What should each element in a text file be terminated by?

A
  • Space * Tab * New-line * EOF character
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the difference between binary and text files?

A
  • Binary files are more efficient but not human-readable * Text files are human-readable but less efficient
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

When should you use text files?

A

For final results if readability is essential

21
Q

What classes simplify file I/O in the uulib package?

A
  • InputFile * OutputFile
22
Q

How do you check for EOF with InputFile?

A

Using the eof() method

23
Q

What does the readInt() method do in InputFile?

A

Returns an integer read from the file

24
Q

What is the purpose of close() method in file handling?

A

To close the file

25
What does BufferedReader.readLine() return if EOF is reached?
null
26
What is a common use case for binary files?
Storing large amounts of data like images or videos
27
What does the PrintWriter class provide?
Print and println methods for writing various types
28
Fill in the blank: The FileOutputStream class is used for _______.
Writing binary files
29
True or False: All files must be closed after operations.
True
30
What is the main drawback of binary files?
Not human-readable
31
What does the InputFile class constructor do?
Opens specified file for input
32
What is the purpose of the FileTotalUnknown class?
To calculate the total of numbers read from a file and print the result.
33
What method is used to read integers from a file in the FileTotalUnknown class?
readInt()
34
What is the output format of the total calculated in the FileTotalUnknown class?
Total is [total]
35
What is the role of the OutputFile class?
To handle output file operations such as creating, closing, and writing data.
36
Which method in OutputFile is used to print a string followed by a new line?
println(String str)
37
How can you write a sequence of integers (1-10) to a file using OutputFile?
By using a loop that calls ofile.println(i) for each integer.
38
What is an example of writing an array of integers to a file?
Using a loop to iterate through the array and calling ofile.println(nums[i]).
39
What is the purpose of creating a reusable method in the FileUtils class?
To write an integer array to a file.
40
What parameters does the writeToFile method in FileUtils take?
int[] nums, String fname
41
In the Bills class, how are total electric and gas bills computed?
By reading from both gas.dat and electric.dat and summing the values.
42
What does the PayRoll class demonstrate?
Reading employee hours and rates from a file and writing their pay to another file.
43
What is the format of each record in the hours.dat file?
Employee number, number of hours worked, and rate per hour.
44
What method is used to check if the end of the file has been reached in the PayRoll class?
eof()
45
In the PayRoll class, how is the pay calculated?
By multiplying hours worked by the rate.
46
What is the output format when writing to pay.dat in the PayRoll class?
Employee number followed by the calculated pay, separated by a tab.
47
What Java I/O classes are used for text input and output stream processing?
FileReader, BufferedReader for input; FileWriter, BufferedWriter, PrintWriter for output.
48
Fill in the blank: The OutputFile class allows you to print a _______ to the file.
[string, integer, float, double]
49
True or False: The FileTotalUnknown class can handle multiple files at once.
False