1/60
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What do streams do?
Transfer data to and from a program
What is an input stream?
Data flowing into the program (reading from a file)
What is an output stream?
Data flowing out of the program (writing to a file)
What are the two types of streams?
Text streams (Characters). Byte streams
Features of Text streams (2)
Handles 16-bit unicode characters
Used for .txt/.csv and source code
What classes are used on text streams? (2)
Reader and Writer
What classes are used on byte streams? (2)
InputStream and OutputStream
Features of Byte streams (2)
Handles raw 8-bit binary data
Used for images/audio and compiled files
What does delimited mean?
Using a character such as space/comma (CSV) or tab to mark the end of a field
What does fixed-width mean?
When every field takes up exactly 4 characters regardless of its value
What are the text packing methods for Text streams (2)
Delimited. Fixed-width
Do byte streams use delimiters?
No
What do byte streams use to separate fields?
Size and order
Both … and … must agree on number of …
Reader. Writer. Bits
What is the “drift” problem?
If input stream reads a smaller value (32) where output stream wrote larger (64)
What does the “drift” problem cause?
Creates error and entire stream becomes garbage
Can java give an error when working with files?
No
Name 2 classes that can handle text files
OutputFile. InputFile
What is the OutputFile Class?
Provides methods to write basic java types to a text file
What is the InputFile Class?
Provides methods to read primitives and Strings back from a text file
What is a path?
Location of a file
What is an absolute path?
Full specific address e.g. C:\Users\Cinema\theater.txt
Negative of absolute files
If the project is moved the path breaks
What is a relative path?
Address relative to the Project Root. e.g. “data/logs.txt” or “theater.txt“
Benefit of relative path
Portability
What is portability
Project is portable without changes
Example of an output file object creation
OutputFIle out = new OutputFile(“bpm.txt“)
What is “out”? (Example of outputfile object creation)
Name of object
What is “new”? (Example of outputfile object creation)
Opens file
What does out.println do? (OutputFile)
Writes value to file
What does out.close do? (OutputFile)
Saves and closes file
What does .eof() return?
Boolean as to whether you are at the end of a file
What should you check before reading from an input file?
If .eof() is false then read
What does it mean when .eof() is false?
There’s still data
What does it mean when .eof() is true?
When end of file is reached
Explain the hierarchal structure of classes
Wrapped inside one another to add functionality
What does FileWriter/FileReader do?
Connects directly to file on disk
What does BufferedWriter/BufferedReader do?
Adds a memory buffer for efficiency
What does PrintWriter do?
Adds high-level methods like println() and printf()
Explain wrapping
Wrap a low-level FileWriter inside a high-level PrintWriter to get disk connectivity + easy formatting
Is Disk access slower or RAM access?
Disk access
Explain the benefit of buffering
Writing 1 byte at a time to hardrive is slow. Fill buffer in RAM then drive to disk
Can you write primitives directly?
Yes using println() PrintWriter class
Benefit of using try with resources (classes in try-catch bracket)
Automatically closes and causes chain-reaction which closes all nested classes
What does .exists() do?
Checks to see if file exists
What does .canRead() do?
Checks to see if file is readable
What does .getAbsolutePath() do?
Gets exact path of file
What does .length() do?
Metadata- finds length of file
What is metadata?
Data about a file e.g. size/name/last modified
What can be used instead of BufferedReader?
Scanner
Benefit of using Scanner (2)
Extract primitives. Allows to check data type before it is read (type-safe reading)
When to use BufferedReader instead of Scanner?
Bulk text
When to use Scanner instead of BufferedReader?
Handles mixed data
Features of text files (3)
Readable (Unicode)
Variable width (1 takes 1 byte. 1000 takes 4)
Sequential
Features of binary files (3)
Machine-readable
Fixed width (int always 4 bytes)
Random access
File types of binary (2)
.dat and .bin
What is sequential access?
Data read in strict order from start to finish
What is random access?
Data accessed via a pointer that jumps to any address
Formula to find byte address
(record index) x (fixed record size)
How is File IO handled in a project
By one class (high cohesion + low coupling)
What is the GIGO Principle?
“Garbage In Garbage Out.” If a corrupt file is loaded the entire code’s logic will fail