集册 Java实例教程 如何使用PushbackInputStream来回读取

如何使用PushbackInputStream来回读取

欢马劈雪     最近更新时间:2020-01-02 10:19:05

493
如何使用PushbackInputStream来回读取


import java.io.ByteArrayInputStream;
/* 
 来自 
*nowjava - 时  代  Java*/

import java.io.IOException;

import java.io.PushbackInputStream;


public class Main {

  public static void main(String[] args) {

    String strExpression = "a = a++ + b;";


    byte bytes[] = strExpression.getBytes();


    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);


    PushbackInputStream pis = new PushbackInputStream(bis);


    int ch;


    try {


      while ((ch = pis.read()) != -1) {

        if (ch == '+') {
        /**
         * N o w  J a v a  .   c o m 提 供 
        **/

          if ((ch = pis.read()) == '+') {

            System.out.print("Plus Plus");

          } else {

            pis.unread(ch);


            System.out.print("+");

          }

        } else {
展开阅读全文