

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to close this input stream and release any system resources associated with the stream
The method java.io.InputStream.close() is used to close this input stream and release any system resources associated with the stream. This method requires no parameters and returns no value. Also, the IOException is thrown when an I/O error occurs.
A program that demonstrates this is given as follows −
Example
import java.io.FileInputStream; import java.io.InputStream; public class Demo { public static void main(String[] args) throws Exception { InputStream i = null; int num = 0; try { i = new FileInputStream("C://JavaProgram//data.txt"); num = i.available(); System.out.println("The number of bytes are: " + num); i.close(); num = i.available(); System.out.println("The number of bytes are: " + num); } catch(Exception e) { System.out.print("Error!!! The input stream is closed"); } } }
The output of the above program is as follows −
Output
The number of bytes are: 4 Error!!! The input stream is closed
- Related Questions & Answers
- Java Program to mark the current position in this input stream
- Difference between the byte stream and character stream classes in Java?
- Character Stream vs Byte Stream in Java
- Java Program to read the next byte of data from the input stream
- Java Stream findAny() with examples
- Java Program to sort String Stream with reversed Comparator
- Stream In Java
- Java Program to convert Stream to List
- Standard Input Stream (cin) in C++
- Java Program to convert Stream to typed array
- Program to convert List to Stream in Java
- Array To Stream in Java
- Stream sorted() in Java
- How to convert an input stream to byte array in java?
- Program to Iterate over a Stream with Indices in Java 8
Advertisements