Results 1 to 2 of 2
Thread: Java i/o confusion
- 02-11-2011, 01:22 PM #1
Member
- Join Date
- Apr 2010
- Location
- london UK
- Posts
- 53
- Rep Power
- 0
Java i/o confusion
hello,
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
java.io.FileInputStream
java.io.BufferedInputStream
java.io.BufferedReader
java.io.Reader
java.io.FileReader
and how do i combine them all?
do i do fileinputstream-> buffer-> reader
or
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
- 02-11-2011, 01:35 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Confusion here @@' Help!
By pleasurelyours in forum New To JavaReplies: 7Last Post: 06-09-2010, 03:42 PM -
java API (SE) version confusion
By Arnold in forum New To JavaReplies: 3Last Post: 04-30-2010, 10:42 AM -
confusion with Design Pttern in java
By sandeepsai39 in forum New To JavaReplies: 2Last Post: 11-23-2009, 07:45 AM -
Tic Tac Toe confusion
By jigglywiggly in forum New To JavaReplies: 15Last Post: 04-12-2009, 01:47 AM -
Confusion over arrays
By dbashby in forum New To JavaReplies: 5Last Post: 04-04-2009, 09:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks