1/20
From Dr. Pittman Lecture Slides
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
File
A collection of 1s and 0s stored on a computer
Absolute File Path
Exact path to a file starting at the root of the file system
Relative File Path
Path to a file relative to the working directory
Aspects of Absolute File Path
Gives name of each folder that needs to be opened. Very tedious and are computer specific
Aspects of Relative File Path
Most programs use this sine it allows for the paths to be more flexible and run on multiple systems
to go down a tree
..
to go up the tree one folder
.
denotes the current directory/folder
File Class
getAbsolutePath()
canWrite()
canRead()
length()
exists()
FileInputStream Class
used to read raw bytes of data from a file; works for any type of file
FileReader
Reads unicode values from the text files; works well to store text data
Input Streams
FileInputStream
FileReader
Read method returns 1 at the end of stream
Scanner Class
Scanner scnr = new Scanner(medicalData);
String id = scnr.next(); (gets next char)
int weight = scnr.nextInt(); (gets next int)
double temperature = scnr.nextDouble(); (gets next double
File Output
FileOutputStream
FileWriter
FileOutputStream Class
FileOutputStream.write(72);
Used to write raw byte data to a file, and can be used to create files of any type
FileWriter Class
FileWriter.write(“H”);
Used to write text data to a file
PrintWriter Class
printWriter.println(“Hello”);
Can be used to wrap an output stream
Gives access to methods normally used for printing to console.
Buffers
allows for data stored in a cache until a certain threshold is reached.
Read Buffer
When empty makes a request to fill in the buffer with data from the designated file
Write Buffer
When full makes a request to write the data to the designated file.
.flush()
force any data currently held in a temporary buffer to be immediately written or transmitted to its final destination