如何将bufferedInputStream集成到字符串?
问题描述:
基本上,我试图通过将现有的BufferedInputStream(System.in)切换到我自己的缓冲输入流来实现击键自动化。我想创建一个BufferedInputStream()对象,该对象附属于可以异步控制的字符串。如何将bufferedInputStream集成到字符串?
这是我想要做什么..
StringBuilder stringBuilder=new StringBuilder;
BufferedInputStream output=new something(new something(stringBuilder));
目前我能看到的唯一选择是检查文件是否存在,然后打开一个缓冲的输入流吧。
我不太确定如何做到这一点,但我需要写一些可以代替System.in inpustream的东西。
答
我把一个良好的坚实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的缓冲读写器中。我可以让它陷入困境,因为它是一个公共静态,这是可能的。现在,我可以像读取和写入我的应用程序一样,在我自己的应用程序中运行命令行。
您的问题很不清楚。你想写'输出'还是读它? – 2013-04-22 21:50:19
我不太明白你要做什么。你想写入StringBuilder,然后再读取你从InputStream中写入的内容吗? – creechy 2013-04-22 23:06:20
基本上,我有一个大型程序,有时我需要做一个大型程序的一部分。所以,我从原来的程序中劫掠stdin和stdout并重定向到读者/作者:)答案在下面,谢谢阅读。 – AdamOutler 2013-04-23 02:52:07