IO Flashcards
What package use for input/output?
import java.io*
What buffering
Java will create intermediate memory called buffer which does reading and writing in the background. If not, then program would have to read one character at a time. This adds efficency
illustration of buffering
What is flushing?
force buffer to write to the file and wont return until its done. Ensures data is on the file before moving on
Byte streams are for what?
Bytes, for binary data. Good for non-text data
Explain character streams and what good for?
text files
What are the 3 predefined streams in java
system.in
system.out
system.err
Does JVM consider Console a byte device?
yes
Scanner is a common Console class. T/F?
yes
Scanner class.
import java.util.scanner
Intro to Files
T/F opening a file for writing will create a new file if it doesnt exist?
true
Writnig and updating files pic
close files after done to save space
What id buffered classes
wrapper class around i/o methods, to use buffer which adds efficeincy
why use try with resource statments
auto-close the file at exit of the try
recap
Can you describe these byte stream wrappers?
InputStream/outputstream topics
fileinput/output stream
example
bytearrayinputstream / output stream
treat bytes like a file
bufferedinput/output stream
creates buffer support - usually perforamnce improvments
explain pushbackinputstream
allows “unreading” read data. push byte back into the input stream buffer. Does not change underlying file.
does not have to pushback data you read
whats printf()
specify format string then data
does printf lineup the columns?
yes… cool
datainputstream output
adds functionality
endless for-loop but traps when end of file exception… kinda cool
randomAccessFile explain
character stream topics
Reader/Writer classes
set up our
parts inventory file so that the part number was contained in a field width of 8, the part name was
contained in a field width of 15, and the part price was contained in a field width of 10 with two values
after the decimal point.
output.printf( “%-8s %-15s %10.2f %n”, “P-100”, “PartNumber100”, 5.25 );
output.printf( “%-8s %-15s %10.2f %n”, “P-101”, “PartNumber101”, 2.10 );
The hyphen (-) in the string formats indicates that the respective objects will be left-justified in their
respective fields. The %n in the format strings specifies that a line separator will be written
How write to file and append to the end of it?
PrintWriter output = new PrintWriter( new FileWriter( f, true) );
The “true” argument in the FileWriter constructor in the above statement allows data to be appended
to the file.