FileIO Flashcards
Which is the simpler searching algorithm to implement?
Linear Search
Which searching algorithm needs to use a sorted list?
Binary Search
What is a text file?
A file consisting of multiple lines of text characters
What classes are not standard in Java I/O?
InputFile and OutputFile classes
What is the purpose of I/O?
Storing data to ‘nonvolatile‘ devices, e.g. Harddrive
What are the two types of streams in Java?
- Text streams * Binary streams
What are the two directions of streams in Java?
- Input * Output
What are the four base-classes dealing with I/O in Java?
- Reader: text-input * Writer: text-output * InputStream: byte-input * OutputStream: byte-output
What character terminates a text file?
The new-line character ‘\n’
What is EOF in file processing?
End-of-file character
What is the general scheme for reading/writing in Java?
- Open an input/output stream * Read/write next data from/to the stream * Close the stream
Which class reads characters from a file?
FileReader Class
What does the BufferedReader class do?
Reads a line of text
What exception might be thrown during I/O operations?
IOException
Try-catch blocks are used for what purpose in I/O?
To handle exceptions
What class is used to write characters to a file?
FileWriter class
What is the benefit of using BufferedWriter?
Provides efficient writing
What should each element in a text file be terminated by?
- Space * Tab * New-line * EOF character
What is the difference between binary and text files?
- Binary files are more efficient but not human-readable * Text files are human-readable but less efficient
When should you use text files?
For final results if readability is essential
What classes simplify file I/O in the uulib package?
- InputFile * OutputFile
How do you check for EOF with InputFile?
Using the eof() method
What does the readInt() method do in InputFile?
Returns an integer read from the file
What is the purpose of close() method in file handling?
To close the file
What does BufferedReader.readLine() return if EOF is reached?
null
What is a common use case for binary files?
Storing large amounts of data like images or videos
What does the PrintWriter class provide?
Print and println methods for writing various types
Fill in the blank: The FileOutputStream class is used for _______.
Writing binary files
True or False: All files must be closed after operations.
True
What is the main drawback of binary files?
Not human-readable
What does the InputFile class constructor do?
Opens specified file for input
What is the purpose of the FileTotalUnknown class?
To calculate the total of numbers read from a file and print the result.
What method is used to read integers from a file in the FileTotalUnknown class?
readInt()
What is the output format of the total calculated in the FileTotalUnknown class?
Total is [total]
What is the role of the OutputFile class?
To handle output file operations such as creating, closing, and writing data.
Which method in OutputFile is used to print a string followed by a new line?
println(String str)
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.
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]).
What is the purpose of creating a reusable method in the FileUtils class?
To write an integer array to a file.
What parameters does the writeToFile method in FileUtils take?
int[] nums, String fname
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.
What does the PayRoll class demonstrate?
Reading employee hours and rates from a file and writing their pay to another file.
What is the format of each record in the hours.dat file?
Employee number, number of hours worked, and rate per hour.
What method is used to check if the end of the file has been reached in the PayRoll class?
eof()
In the PayRoll class, how is the pay calculated?
By multiplying hours worked by the rate.
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.
What Java I/O classes are used for text input and output stream processing?
FileReader, BufferedReader for input; FileWriter, BufferedWriter, PrintWriter for output.
Fill in the blank: The OutputFile class allows you to print a _______ to the file.
[string, integer, float, double]
True or False: The FileTotalUnknown class can handle multiple files at once.
False