Solved

java.io question

Posted on 2006-07-02
6
256 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now