Advertisements
Home > Java > Java Program by using BufferedReader stream to use mark and reset methods – Q39

Java Program by using BufferedReader stream to use mark and reset methods – Q39


Q39: Java Program by using BufferedReader stream to use mark and reset methods.

import java.io.*;
class Buf_Inp_Stream{
	public static void main(String args[]) throws IOException{
		String str = "This is s © copyright symbol " +
					 "but this is &copy not.";
		byte buf[] = str.getBytes();
		ByteArrayInputStream in = ByteArrayInputStream(buf);
		BufferedInputStream f = new BufferedInputStream(in);
		int c;
		boolean marked = false;
		while((c = f.read()) != -1){
			switch(c){
				case '&':
					if(!marked){
						f.mark(32);
						marked = true;
					}
					else{
						marked = false;
					}
					break;
				case ';':
					if(marked){
						marked = false;
						System.out.print("(c)");
					}
					else{
						System.out.print((char) c);
					}
					break;
				case ' ':
					if(marked){
						marked = false;
						f.reset();
						System.out.print("&");
					}
					else{
						System.out.print((char) c);
					}
					break;
				default:
					if(!marked)
						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: