---
title: "How to use PushbackInputStream class in java"  
description: "How to use PushbackInputStream class in java"  
author: "Simond Gear"  
published: 2016-11-07  
updated: 2016-11-07  
canonical: https://www.mindstick.com/forum/34201/how-to-use-pushbackinputstream-class-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How to use PushbackInputStream class in java

Hi Guys\
I am [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in java [programming language](https://www.mindstick.com/articles/329035/5-most-in-demand-programming-languages-to-consider-for-your-app-development-in-2022) and i want to use PushbackInputStream class.Please [explain me](https://www.mindstick.com/forum/34220/can-anyone-explain-me-about-off-page-activity) with the help of program.\
I would really appreciate your help.\
Thanks

## Replies

### Reply by Hubert Jason

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; } } } }
```

\

### Reply by Mark Devid

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();}}
```


---

Original Source: https://www.mindstick.com/forum/34201/how-to-use-pushbackinputstream-class-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
