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
Q

What does BufferedReader.readLine() return if EOF is reached?

26
Q

What is a common use case for binary files?

A

Storing large amounts of data like images or videos

27
Q

What does the PrintWriter class provide?

A

Print and println methods for writing various types

28
Q

Fill in the blank: The FileOutputStream class is used for _______.

A

Writing binary files

29
Q

True or False: All files must be closed after operations.

30
Q

What is the main drawback of binary files?

A

Not human-readable

31
Q

What does the InputFile class constructor do?

A

Opens specified file for input

32
Q

What is the purpose of the FileTotalUnknown class?

A

To calculate the total of numbers read from a file and print the result.

33
Q

What method is used to read integers from a file in the FileTotalUnknown class?

34
Q

What is the output format of the total calculated in the FileTotalUnknown class?

A

Total is [total]

35
Q

What is the role of the OutputFile class?

A

To handle output file operations such as creating, closing, and writing data.

36
Q

Which method in OutputFile is used to print a string followed by a new line?

A

println(String str)

37
Q

How can you write a sequence of integers (1-10) to a file using OutputFile?

A

By using a loop that calls ofile.println(i) for each integer.

38
Q

What is an example of writing an array of integers to a file?

A

Using a loop to iterate through the array and calling ofile.println(nums[i]).

39
Q

What is the purpose of creating a reusable method in the FileUtils class?

A

To write an integer array to a file.

40
Q

What parameters does the writeToFile method in FileUtils take?

A

int[] nums, String fname

41
Q

In the Bills class, how are total electric and gas bills computed?

A

By reading from both gas.dat and electric.dat and summing the values.

42
Q

What does the PayRoll class demonstrate?

A

Reading employee hours and rates from a file and writing their pay to another file.

43
Q

What is the format of each record in the hours.dat file?

A

Employee number, number of hours worked, and rate per hour.

44
Q

What method is used to check if the end of the file has been reached in the PayRoll class?

45
Q

In the PayRoll class, how is the pay calculated?

A

By multiplying hours worked by the rate.

46
Q

What is the output format when writing to pay.dat in the PayRoll class?

A

Employee number followed by the calculated pay, separated by a tab.

47
Q

What Java I/O classes are used for text input and output stream processing?

A

FileReader, BufferedReader for input; FileWriter, BufferedWriter, PrintWriter for output.

48
Q

Fill in the blank: The OutputFile class allows you to print a _______ to the file.

A

[string, integer, float, double]

49
Q

True or False: The FileTotalUnknown class can handle multiple files at once.