Home > Java > Java Program by using PushBackReader to utilize unread method – Q40

Java Program by using PushBackReader to utilize unread method – Q40

January 20, 2009 Leave a comment Go to comments

Q40: Java Program by using PushBackReader to utilize unread method.

import java.io.*;

class PB_Inp_Stream{
	public static void main(String args[]) throws IOException{
		String s = " if (a== 4) a = 0;\n";
		byte buf[] = s.getBytes();
		ByteArrayInputStream in = ByteArrayInputStream(buf);
		PushbackInputStream f = PushbackInputStream(in);
		int c;
		
		while((c = f.read()) != -1){
			switch(c){
				case '=':
					if((c = f.read()) != -1){
						System.out.print(".eq.");
					}
					else{
						System.out.print("<-");
						f.unread();
					}
					break;
				default:
					System.out.print((char) c);
					break;
			}
		}
	}
}

… from College notes (BCA/MCA assignments):


Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: