5. I/O & NIO Flashcards
What is the File class?
the file class isn’t used to actually read or write data; its used to work at a higher level, making new empty files, searching for files, deleting files, making directories en working with paths.
What is the FileReader class?
this class is used to read character files. Its read() methods allowing you to read single characters, the whole stream of characters or a fixed number of characters. FileReaders are wrapped by higher-level objects (BufferedReaders)
What is the BufferedReader class?
this class is used to make lower-level Reader classes (FileReader) more
efficiënt and easier to use. BufferedReaders read relatively large chunks of data from a file at
once and keep this data in a buffer.
What is the FileWriter class?
this class is used to write to character files. Its write() allow you to write characters or strings to a file. These are wrapped by higher-level writer objects (BufferedWriters or PrintWriters)
What is the BufferedWriter class?
this class is used to make lower-level Writer classes (FileWriter) more efficiënt and easier to use. It writes relatively large chunks of data to a file at once.
What is the PrintWriter class?
because of newly created methods and contructors you might find that you can
use PrintWriter in places where you previously needed a wirter to be wrapped. New
methods make printwriter quite flexible and powerful
What is the FileInputStream class?
this class is used to read bytes from files and can be used for binary as well as tekst. We use FileInputStream with higher-level objects (ObjectInputStream)
What is the FileOutputStream class?
this class used to write bytes to files. We use FileOutputStream with higher- level objects (ObjectOutputStream)
What is the ObjectInputStream class?
this class is used to read an input stream and deserialize objects. Its used with FileOutputStream so that you can read objects rather than characters or bytes. This proces is called deserialisation
What is the ObjectOutputStream class?
this class is used to write objects to an ouput stream and is used with classes like FileOutputStream to write to a file (serialization)
What is the Console class?
this class provides methods to read input from the console and write formatted output to the console.
What are Objects of type File representing?
Objects of type File are used to represent the actual files(but not the data in the files) or directories that exist on a computers physical disk.
Does new File(); creates a file?
No
What does boolean createNewFile(); do?
Returns true if the named file does not exist and was successfully created; returns cals if the named file already exist
What does boolean exists(); do?
The exists() look if the named file already exists
What does the code FileWriter fw = new FileWriter(file); do?
does two things:
- It created a FileWriter reference variable (fw), and a FileWriter object, then assigned to fw
- It created an actual empty file out on the disk
What happens when you write data out to a stream?
When you write data out to a stream, some amount of buffering will occur, and you never know for
sure exactly when the last data will actually be sent.
What does the flush() method do?
invoking the flush() method guarantees that the last of the data you thought you had already written actually gets out to the file.