[英]Reading stream from infinite loop
I'm trying out some socket programming in Java for a little project.我正在为一个小项目尝试一些 Java 套接字编程。 I've ran into a problem reading an infinite InputStream from an external process.
我在从外部进程读取无限 InputStream 时遇到了问题。 The program goes into an infinite loop.
程序进入无限循环。
I suspect that readLine() have to read the stream until EOF.我怀疑 readLine() 必须读取流直到 EOF。
I've put some print statements and I'm sure that the program reaches the while-loop.我已经放置了一些打印语句,并且我确信程序到达了 while 循环。
This is my method:这是我的方法:
public void run() throws IOException {
Process p = Runtime.getRuntime() .exec(exe);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = in.readLine()) != null){
System.out.println(line);
dout.writeUTF(" " + line + " yes!");
dout.flush();
}
in.close();
dout.close();
s.close();
ss.close();
}
正如@codeflush.dev 提到的,流没有到达 EOF,因此 readLine 不是一个可行的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.