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

Java Program by using PushBackReader to utilize unread method – Q40


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):


Advertisements
  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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: