Java i/o confusion
i want to read a file. (text)
and now i am hopelessly confused over all the i/o file/ input/ reader classes.
In a later version I want to be able to set the (UniCode)Character set but what is the diffrence between
and how do i combine them all?
do i do fileinputstream-> buffer-> reader
2 related questions.
1) I also would like to include:
javax.swing.ProgressMonitorInputStream (to see the progress of the input)
do i do fileInputStream-> monitor -> buffer-> reader
or fileinputstream-> buffer -> monitor -> reader
or fileinputstream-> monitor -> reader -> buffer
or even another variation?
2) which classes do I declare as instance variables (defined in class, private) and which as temporarely objects (declared in the constructor)
Thanks in advance
There are two types of input streams: byte oriented (all the InputStreams take care of that) and character oriented (all the Readers take care of it). There's bridge that converts a byte oriented input stream to a character oriented inputstream: the InputStreamReader. It needs an encoding to convert those bytes to characters. A default encoding is also available. So if you want to read text (characters) with a certain encoding you open a FileInputStream (assuming you want to read from a file); this gives you a byte oriented input stream. Wrap it in an InputStreamReader with the encoding you want to use; this gives you a character oriented stream. If you want to can wrap that reader in another reader, e.g. a BufferedReader to speed up the actual reading.
Originally Posted by willemien