InputStream Close() Example
Closes this input stream and releases any system resources associated with the stream.
InputStreamclass Close() method example. This example shows you how to use Close() method.This method Closes this input stream and releases any system resources associated with the stream.
Here is the code:-
/**
* @Program that Closes this input stream and releases any system resources
associated with the stream.
* Close.java
* Author:-RoseIndia Team
* Date:-06-Jun-2008
*/
import java.io.*;
public class Close extends InputStream {
public int read() throws IOException {
return 0;
}
public static void main(String[] args) throws IOException {
PipedInputStream i = new PipedInputStream();
OutputStream o = new PipedOutputStream();
i.connect((PipedOutputStream) o);
byte[] b = {1, 2, 3, 4, 5, 6, 7};
o.write(b);
System.out.print("The estimate of the number of bytes that can be read : ");
while (i.available() != 0) {
System.out.print(" "+i.read());
}
//Closes this input stream
i.close();
}
} |
Output of the Program
| The estimate of the number of bytes that can be read : 1 2 3 4 5 6 7 |
|