The close() method is a built-in method of the Java.io.ByteArrayInputStream closes the input stream and releases system resources associated with this stream to Garbage Collector.
Syntax:
public void close()
Parameters: The function does not accepts any parameter.
Return Value: The function returns nothing.
Below is the implementation of the above function:
Program 1:
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
byte [] buffer = { 1 , 2 , 3 , 4 };
ByteArrayInputStream geek
= new ByteArrayInputStream(buffer);
int number = geek.available();
System.out.println( "Use of available() method : "
+ number);
geek.close();
}
}
|
Output:
Use of available() method : 4
Program 2:
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
byte [] buffer = { 2 , 3 , 4 , 8 , 9 };
ByteArrayInputStream geek
= new ByteArrayInputStream(buffer);
int number = geek.available();
System.out.println( "Use of available() method : "
+ number);
geek.close();
}
}
|
Output:
Use of available() method : 5
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/ByteArrayInputStream.html#close()