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




