使用Fedora12:mkfifo pipe创建管道。
当我使用以下代码尝试打开指定管道的输入流时,它会在FileInputStream构造函数上阻塞,除非我创建管道的写入器,例如打开另一个终端并运行:
tee pipepublic static void main(String[] args){
try {
File pipe = new File("/tmp/pipes_debugging/pipeToJava");
System.out.println( pipe.canRead() );
FileInputStream fis = new FileInputStream(pipe);
System.out.println("exiting.");
} catch (Exception e) {
e.printStackTrace();
}
}输出:
true
<blocks - thread trace shown below>Thread [main] (Suspended)
FileInputStream.open(String) line: not available [native method]
FileInputStream.<init>(File) line: 137
PipesDebugging.main(String[]) line: 12 发布于 2011-08-21 04:09:02
从评论中复制:
这似乎是一种正确的行为。你想干嘛?-7点42分班萨20号
是的,我想这个线程可能刚刚回答了我的问题:stackoverflow.com/questions/2246862/… -我试图从管道中读取,我期望流在read()时打开并阻塞,而不是在打开流时阻塞。-大卫·帕克斯6月20日7:52
https://stackoverflow.com/questions/6408099
复制相似问题