Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are prepackaged character stream classes?

Tags:

java

io

While reading Java Tutorials, the topic Basic I/o says, use InputStreamReader and OutputStreamWriter when there are no prepackaged character stream classes.

1)What are Pepackaged character stream classes? Does it mean, a file already has some text!

like image 544
Sampath Kumar Madala Avatar asked Nov 30 '25 03:11

Sampath Kumar Madala


2 Answers

The term is quite vague and doesn't really seem to be defined anywhere, so good question.

As best I understand it it means things like FileInputStream, FileOutputStream, ByteArrayOutputStream, etc. Classes that have wrapped up a particular kind of stream for you and provide the functionality required to work with it.

Note that most of these streams are working with characters not bytes, and that is generally what you want in Java for dealing with String data in files. On the other hand though if you are reading a pure binary source then the data will come in as bytes and you can then use InputStreamReader to convert those bytes to characters.

So a prepackaged stream reader is one that already provides you the data pre-packaged in the form that you want it.

like image 133
Tim B Avatar answered Dec 02 '25 17:12

Tim B


I believe it to mean classes which inherit Reader or Writer. Such classes "wrap" byte streams so as to convert them automatically to character streams. Example: FileReader, FileWriter; they can read text from files directly.

If no such classes exist for your particular stream needs but you know what you get out of it/put into it is text, then you must use these two wrapper classes.

Classical example: HTML. It is text, but what you get from sockets is byte streams; if you want to read it as HTML, use a Reader (with the correct encoding!) over the socket stream (but of course, many APIs today don't require you to do that).

like image 23
fge Avatar answered Dec 02 '25 17:12

fge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!