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 © 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):
Categories: Java
Java File Handling, Java IO Programs
Comments (0)
Trackbacks (0)
Leave a comment
Trackback