12:05 am - Saturday June 24, 2017

BufferedInputStream example program for close() 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 close() in java
 */

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

public class ReadFileUsingBufferedInputStream {

	public static void main(String[] args) {
		File file = new File("F:/Vikram/StaticInit.java");
		BufferedInputStream bin = null;
		try {
			FileInputStream fin = new FileInputStream(file);
			bin = new BufferedInputStream(fin);
			while (bin.available() > 0) {
				System.out.print((char) bin.read());
			}
		} catch (FileNotFoundException e) {
			System.out.println("File not found" + e);
		} catch (IOException ioe) {
			System.out.println("Exception while reading the file " + ioe);
		} finally {
			try {
				if (bin != null)
					bin.close();
			} catch (IOException ioe) {
				System.out.println("Error while closing the stream : " + ioe);
			}
		}
	}
}

Output

class A
{
{
System.out.print(“Init”);
}
Static
{
System.out.print(“Static”);
}
A()
{
System.out.print(“Constructor”);
}
}

BACK

Filed in: Z-A All Java Codes

Comments are closed.