• Post Reply Bookmark Topic Watch Topic
  • New Topic

cryptic I/O

 
Amit Badle
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
I/O & streams in java seems a bit cryptic than in most langs. and also that it is a teeny-weeny bit harder to understand the hierarchy and importance of so many classes for I/O & streams. can any guru put some light here and can the present I/O scenario be changed in furute jdk's.
amit
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'm far from an I/O guru, but let me try to summarize the IO classes. The classes named xxxxxReader or xxxxxWriter are used to read and write characters. The classes named xxxxxStream are used to read and write bytes. There is a class called InputStreamReader and one called OutputStreamWriter that are used to convert a stream from bytes to characters. Those are the basics.
Now, lets say we start with an InputStream or an OutputStream. Those are byte streams. Suppose that we want to read those streams as characters. How can we add the ability to read characters to our stream? We can "wrap" other I/O classes around our stream.

Now we can use our InputStreamReader, isr, to read characters from our byte stream, System.in. Now let's say we want to add the ability to buffer the input that we are reading to improve the efficiency of our program. We can "wrap" another class around our InputStreamReader.

Now we have a BufferedReader that is processing the input from System.in. The I/O classes wrap around each other in this way to provide different levels of functionality in the processing of streams. Each class adds its own features and each one is appropriate in certain situations, depending on what you are trying to do with your stream.
HTH
 
Amit Badle
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey bodie,
thast a neat reply u have given and sure u can promulgate urself 2 b a guru ot I/O.
but lets go back in the annals of time. first v had the xxxxxStream classes for 8 bit streams. then v had the xxxxxReader and writer classses for 16 bit streams which are like wrappers. the 8 bit streams wer then deprecated( converted 2 16 bit if i'm not wrong). my question is cant I/O be a bit simpler as this is a bit taxing 4 a dunce like me. b/c other langs that i have learnt the I/O is simpler than this. and how can it be made simpler?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really know of any way to make java I/O simpler. [Scratching my head] I guess that question takes a longer view of the language. I suspect that some of the complexity in the I/O classes result from trying to do OS specific tasks, like disk I/O, in OS non-specific ways that guarantee portability. To be honest, I don't really know what is planned for the next release of the JDK. Maybe the architects have had the same thought as you? Or maybe they are satisfied with the current I/O classes? I don't know.
BTW, the only two classes that are depricated from java.io are LineNumberInputStream and StringBufferInputStream. These two are not some of your heavy-hitting all-star classes anyway.
 
Amit Badle
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
u mayb right in 1 way that 2 ensure portability the I/O model seems very difficult 2 use. but then thats 4 the present. what do v get in the future... lets hope it is easier.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!