Code Example for BufferedInputStream: available() method

BufferedInputStream available() method returns the total count of bytes that can be read or skipped over from the input stream without blocking by next invocation of a method for the input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

/*
 * *********************************************************************************
 *  * Created on 2011 Copyright(c) https://kodehelp.com All Rights Reserved.
 *  *********************************************************************************
 */

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * Created by kodehelp.o.in
 * User: Vigilance.co.in
 * Date: 3/20/11
 * Time: 3:49 PM
 */
public class BufferedInputStreamAvailable {
    public static void main(String args[]) throws IOException {

        FileInputStream fileInputStream = new FileInputStream(new File("/test.txt"));
	    BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        if (bufferedInputStream.available() > 0) {
            do {
                System.out.println((char) bufferedInputStream.read());
            } while (bufferedInputStream.available() > 0);
        }
        bufferedInputStream.close();

    }
}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.