Solved

java.io question

Posted on 2006-07-02
6
246 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

705 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

15 Experts available now in Live!

Get 1:1 Help Now