Java PushbackInputStream (InputStream in) Constructor
Syntax
PushbackInputStream(InputStream in) constructor from PushbackInputStream has the following syntax.
public PushbackInputStream(InputStream in)
Example
In the following code shows how to use PushbackInputStream.PushbackInputStream(InputStream in) constructor.
//www .j av a 2 s . c o m
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;
public class Main {
public static void main(String args[]) throws IOException {
byte buf[] = "== = ".getBytes();
PushbackInputStream f = new PushbackInputStream(new ByteArrayInputStream(buf));
int c;
while ((c = f.read()) != -1) {
switch (c) {
case '=':
c = f.read();
if (c == '=')
System.out.print(".eq.");
else {
System.out.print("=");
f.unread(c);
}
break;
default:
System.out.print((char) c);
break;
}
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »