import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PushbackReader; public class PushbackTest {
public static void main(String[] args) {
try {
var pr = new PushbackReader(new FileReader("src/com/company/PushbackTest.java"),);
{
var buf = new char[];
var lastContent = "";
var hasRead = ; while ((hasRead = pr.read(buf)) > ){
var content = new String(buf, ,hasRead);
var targetIndex = ;
if ((targetIndex = (lastContent + content).indexOf("new PushbackReader")) > ){ pr.unread((lastContent+content).toCharArray()); if (targetIndex > ){
buf = new char[targetIndex];
}
pr.read(buf, , targetIndex);
System.out.println(new String(buf,, targetIndex));
System.exit();
}
else {
System.out.println(lastContent);
lastContent = content;
}
}
} } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
output:
package com.company; import j
ava.io.FileNotFoundException;
i
mport java.io.FileReader;
impor
t java.io.IOException;
import j
ava.io.PushbackReader; public
class PushbackTest {
publi
c static void main(String[] args
) {
try {
var pr =