How to use PushbackInputStream class in java

Total Post:26

Points:182
Java 
 885  View(s)
Ratings:
Rate this:
Hi Guys

I am beginner in java programming language and i want to use  PushbackInputStream class.Please explain me with the  help of program.

I would really appreciate your help.

Thanks
  1. Post:102

    Points:714
    Re: How to use PushbackInputStream class in java

    Hi Simond


    Check this program.I hope it will help you.

    public class PrintCalc {
    public static void main(String args[]) {
    PrintCalc app = new PrintCalc();
    try {
    app.readAndPrint();
    } catch (IOException e) {
    System.out.println("Error encountered during
    printing");
    }
    } private void readAndPrint() throws IOException {
    PushbackInputStream f = new PushbackInputStream(System.in, 3);
    int c, c1, c2;
    while ((c = f.read()) != 'q') {
    switch (c) {
    case '.':
    System.out.print((char) c);
    if ((c1 = f.read()) == '0') {
    if ((c2 = f.read()) == '0') {
    System.out.print("**");
    } else {
    f.unread(c2);
    f.unread(c1);
    }
    } else {
    f.unread(c1);
    }
    break;
    default:
    System.out.print((char) c);
    break;
    }
    }
    f.close();
    }
    }

      Modified On Nov-07-2016 01:47:48 AM
  1. Post:6

    Points:42
    Re: How to use PushbackInputStream class in java

    Hey Simond check this program:



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

    break; 
    default: 
    System.out.print((char) c); 
    break; 



    }

      Modified On Apr-11-2018 05:39:42 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!