- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Java Program to mark the current position in this input stream
- Java Program to read the next byte of data from the input stream
- Java Program to sort String Stream with reversed Comparator
- Java Program to convert Stream to List
- Java Stream findAny() with examples
- Difference between the byte stream and character stream classes in Java?
- How to convert an input stream to byte array in java?
- Java Program to convert Stream to typed array
- Program to convert List to Stream in Java
- Program to Iterate over a Stream with Indices in Java 8
- Character Stream vs Byte Stream in Java\n
- Standard Input Stream (cin) in C++
- Stream In Java
- Program to convert Primitive Array to Stream in Java
- Program to convert Stream to an Array in Java

Advertisements