3:11 pm - Saturday November 25, 8648

BufferedInputStream example program for reset() 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: in JAVA example program for
 */
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class BufferedInputStreamDemo {
	public static void main(String[] args) throws Exception {
		InputStream iStream = null;
		BufferedInputStream bis = null;
		try {
			// read from file c:/test.txt to input stream
			iStream = new FileInputStream("c:/test.txt");
			// input stream converted to buffered input stream
			bis = new BufferedInputStream(iStream);
			// read and print characters one by one
			System.out.println("Char : " + (char) bis.read());
			System.out.println("Char : " + (char) bis.read());
			System.out.println("Char : " + (char) bis.read());
			// mark is set on the input stream
			bis.mark(0);
			System.out.println("Char : " + (char) bis.read());
			System.out.println("reset() invoked");
			// reset is called
			bis.reset();
			// read and print characters
			System.out.println("Char : " + (char) bis.read());
			System.out.println("Char : " + (char) bis.read());
		} catch (Exception e) {
			e.printStackTrace();
		} finally {

			// releases any system resources associated with the stream
			if (iStream != null)
				iStream.close();
			if (bis != null)
				bis.close();
		}
	}
}

Output

Char : A
Char : B
Char : C
Char : D
reset() invoked
Char : D
Char : E

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.