我为此投入了 10 个小时的坚实时间……这就是我想出的……管道流是我需要的
int BUFFER = 4096;
PipedOutputStream toAppPipedOutputStream;
PipedInputStream toAppPipedInputStream;
static BufferedReader fromAppBufferedReaderfinal;
BufferedOutputStream fromAppOutputStream;
PipedOutputStream fromAppPipedOutputStream;
PipedInputStream fromAppPipedInputStream;
/* constructor sets up logging and parameters */
try {
fromAppPipedInputStream = new PipedInputStream(BUFFER);
fromAppOutputStream=new BufferedOutputStream(new PipedOutputStream(fromAppPipedInputStream));
fromAppBufferedReaderfinal=new BufferedReader(new InputStreamReader(fromAppPipedInputStream));
CASUAL.Log.out = new PrintStream(fromAppOutputStream);
toAppPipedInputStream = new PipedInputStream(BUFFER);
toAppPipedOutputStream=new PipedOutputStream(toAppPipedInputStream);
CASUAL.CASUALInteraction.in= new BufferedReader(new InputStreamReader(toAppPipedInputStream));
在我的日志和输出类中,默认情况下,我正在写入指向 System.in 的缓冲读取器/写入器。我可以劫持它,因为它是一个公共静态,这是可能的。现在我可以读取和写入我的应用程序,就好像它在我自己的应用程序内的命令行上运行一样