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
Solved

java.io question

Posted on 2006-07-02
6
269 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 58
maven disable workspace resolution 1 22
Cisco ASA: Java web start no go, asdm launcher no go 3 37
Java 8 to Java 6 8 21
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

838 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