Java.io.FilterWriter.available() Method
Advertisements
Description
The java.io.FilterWriter.available() method returns an the number of bytes that can be read from this input stream without blocking by the next invocation of a method from this input stream.
Declaration
Following is the declaration for java.io.FilterWriter.available() method:
public int available()
Parameters
NA
Return Value
The method returns the number of bytes that can be read.
Exception
IOException -- If an I/O error occurs.
Example
The following example shows the usage of java.io.FilterWriter.available() method.
package com.tutorialspoint;
import java.io.FileInputStream;
import java.io.InputStream;
public class InputStreamDemo {
public static void main(String[] args) throws Exception {
InputStream is = null;
int i=0;
char c;
try{
// new input stream created
is = new FileInputStream("C://test.txt");
// read till the end of the stream
while((i=is.read())!=-1)
{
// convert integer to character
c = (char)i;
// print
System.out.println("Character Read: "+c);
}
}catch(Exception e){
// if any I/O error occurs
e.printStackTrace();
}finally{
// releases system resources associated with this stream
if(is!=null)
is.close();
}
}
}
Assuming we have a text file c:/test.txt, which has the following content. This file will be used as an input for our example program:
ABCDEF
Let us compile and run the above program, this will produce the following result:
Character Read: A Character Read: B Character Read: C Character Read: D Character Read: E Character Read: F