Java-source: Exemple d’utilisation de PushbackInputStream

Author:

Java-source: Exemple d'utilisation de PushbackInputStream
Download

/***** Code de MesExemples.com *******/
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;
 
class ExemplePushbackInputStreamEnJava {
 
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
{
 
 /* Lecture des opérateurs + en priorité */
while( (ch = pis.read())!= -1)
{
if(ch == '+')
{
if( (ch = pis.read()) == '+')
{
System.out.print("Plus Plus");
}
else
{
 
pis.unread(ch);
 
System.out.print("+");
}
}
else
{
System.out.print((char)ch);
}
}
}
catch(IOException ioe)
{
System.out.println("Exception de lecture stream" + ioe);
}
}
}

Cet article Java-source: Exemple d’utilisation de PushbackInputStream est apparu en premier sur .