12:36 am - Monday August 21, 2017

BufferedInputStream example program for available() in java

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
 * @author   candidjava
 * @description:BufferedInputStream example program for available() in java
 */
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;

public class BufferedInputStreamAvailable {
	public static void main(String[] args) {

		try {
			FileWriter fw = new FileWriter("BVS.txt");
			BufferedWriter bw = new BufferedWriter(fw);
			bw.write("Hello Java");
			bw.flush();
			bw.close();
			// FileReader fr=new FileReader("out.txt");
			FileInputStream fis = new FileInputStream("out.txt");
			BufferedInputStream bis = new BufferedInputStream(fis);
			while (bis.available() > 0) {

				Integer bytes = bis.available();
				System.out.print("Available bytes:" + bytes);
				char ch = (char) bis.read();
				System.out.println(" " + ch);

			}
		}

		catch (IOException io) {
			System.out.print("IOException" + io);
		}
	}
}

Output

Available bytes:10 H
Available bytes:9 e
Available bytes:8 l
Available bytes:7 l
Available bytes:6 o
Available bytes:5
Available bytes:4 J
Available bytes:3 a
Available bytes:2 v
Available bytes:1 a

BACK

Filed in: Z-A All Java Codes

Comments are closed.