Solved

java.io question

Posted on 2006-07-02
6
285 Views
Last Modified: 2010-03-31
Hi guys,

As you all know that I am going to learn more about java.io as this is the area where I am not very familiar with. I was planning to start it on this week (hopefully). As I do not have much time, I just would like to have some explanations from you all.

Look at http://java.sun.com/docs/books/tutorial/figures/essential/io-readerapi.gif

Honestly, I am a little bit *scared* when looking at so many types of InputStream as well as OutputStream ;).

Are they all used? As far as I can remember, I normally used FileInputStream and ByteArrayInputStream. How about others (SequenceInputStream, PipedInputStream)? What are they used for?

PS. I may not be able to reply you as fast as I normally did.

Thanks
David
0
Comment
Question by:suprapto45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 17028578
They are all used when needed :)

SequenceInputStream is used when you want to treat multiple input streams as one sequential stream.
eg. if you had a method that required an input stream as input and what you wanted to pass to it was the concatenation of the contents of two files. In this case you would use something like:

InputStream file1 = new FileInputStream(file1);
InputStream file2 = new FileInputStream(file2);
InputStream concatenated = new SequenceInputStream(file1, file2);

processStream(concatenated);

PipedInputStream/PipedOutputStream are used to 'connect' input and output pipes. ie. to pass the output of one stream as the input into another. Its a fairly simple implementation and only useful in simple cases.
0
 
LVL 16

Author Comment

by:suprapto45
ID: 17028766
Thanks objects,

Are they commonly used?

In your opinion, which area of java.io that I should learn first?

Thanks
David
0
 
LVL 92

Assisted Solution

by:objects
objects earned 300 total points
ID: 17028779
not really that common.

Learrn the basics of base classes InputStream and OutputStream first (and Reader/Writer). In most cases you're application will only be dealing with these classes anyway, creating

for example to read a file, you'd typically write:

InputStream in = new FileInputStream(file);

and not

FileInputStream in = new FileInputStream(file);

As you generally don't need to use any of FileInputStream specific methods.
ie. first learn how to use streams (regardless of what type).

The most common used in general are File, Byte, Buffered, Object
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:suprapto45
ID: 17028785
Thanks objects,

I will keep this thread open for one more day to see what others think.

Thanks
David
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 50 total points
ID: 17029362
Hi suprapto45

just to add on what objects said, bare in mind that in the java.io package you will find both readers and streams. Readers and writers deal with text (i.e. text files etc) while streams deal with binary data (i.e. bytes, images etc).

Cheers
0
 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 50 total points
ID: 17029735
Hi suprapto45,

once you're familiar with FileInputStream and FileOutputStream, you can try using java.net.sockets, invoke getInputStream and getOutputStream methods, and use theses streams to communicate.

You can also try output with System.out (java.io.PrintStream), and read line from console System.in (java.io.InputStream)  using a java.io.InputStreamReader and  java.io.BufferedReader.readLine()
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question