?
Solved

java.io question

Posted on 2006-07-02
6
Medium Priority
?
289 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 1200 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 1200 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
Technology Partners: 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 200 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 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 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