![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Advertisements