available(): This method is available in the java.io.FileInputStream class of Java.
Syntax:
int java.io.FileInputStream.available() throws IOException
This method returns an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
Note: Returns 0 when the file position is beyond EOF.
Parameters: NA
Returns: an estimate of the number of remaining bytes that can be read(or skipped over) from this input stream without blocking.
Throws:
1. IOException - if this file input stream has been closed by calling close or an I/O error occurs.
Approach
Java
import java.io.File;import java.io.FileInputStream;import java.io.IOException;public class FileInputStreamavailable {public static void main(String[] args) throws IOException {String pathname = "D:\\hello.txt";File file = new File(pathname);FileInputStream fileInputStream =new FileInputStream(file);try {System.out.println(fileInputStream.available());} catch (IOException e) {System.out.println("Error occured");}fileInputStream.close();}}
Output:
0
No comments:
Post a Comment