13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java Input and Outputnew SequenceInputStream(new FileInputStream("input2.bin"),newFileInputStream("input3.bin"))));You can also create an Enumeration of the files. First, create a reusableArrayEnumerator class:public class ArrayEnumerator implements Enumeration {private int n = 0;private Object[] objects;public ArrayEnumerator(Object[] objects) {this.objects = objects;}}public boolean hasMoreElements() {return n < objects.length;}public Object nextElement() {return objects[n++];}Then you can use it in the SequenceInputStream as follows:BufferedInputStream in = new BufferedInputStream(new SequenceInputStream(new ArrayEnumerator(new Object[] {newFileInputStream("input1.bin"),newFileInputStream("input2.bin"),newFileInputStream("input3.bin"),})));Creating Your Own FiltersIf you want to create your own filter, you can subclass one of the followingclasses:• FilterInputStream• FilterOutputStream• FilterReader• FilterWriterThese classes provide some nice default support, such as handling the close()cascading.Java Input and Output -36© 1996-2003 jGuru.com. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!