Text and Binary Files
Text files
Connect a character input stream to a file
A subset of the Reader hierarchy
Reader <> BufferedReader InputStreamReader FileReader
Notes
- All classes in the java.io package that end with Reader are members of the Reader hierarchy.
- Although you can read files with the FileReader class alone, the BufferedReader class improves efficiency and provides better methods for reading character input streams.
Classes used to connect to a file with a buffer
BufferedReader contains methods for reading data from the stream ->FileReader connects the stream to a file
Constructors of these classes
Constructor | Throws |
---|---|
BufferedReader(Reader) | None |
FileReader(File) | FileNotFoundException |
FileReader(StringFileName) | FileNotFoundException |
How to connect a character input stream to a file
BufferedReader in = new BufferedReader(new FileReader(productsFile));