3:06 pm - Saturday September 26, 2787

FileInputStream 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
/**
@program : FileInputStream example program for close() in java
@author  : "candid"
@date    : 29.10.12
 */

import java.io.FileInputStream;
import java.io.IOException;

public class FISDemo {
	public static void main(String[] args) throws IOException {
		FileInputStream fis = null;
		int available = 0;
		int i = 0;
		try {
			fis = new FileInputStream("E:/karthi/FIStream1/src/a.txt");
			while ((i = fis.read()) != -1) {
				available = fis.available();
				char c = (char) i;
				System.out.print("Available :" + available);
				System.out.println(" Read :" + c);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (fis != null) {
				fis.close();
			}
		}
	}
}

Output

Available :5 Read :K
Available :4 Read :A
Available :3 Read :R
Available :2 Read :T
Available :1 Read :H
Available :0 Read :I

BACK

Filed in: Z-A All Java Codes

Comments are closed.