为什么 java 的 RandomAccessFile 不是 linux 上的 return?

Why does java's RandomAccessFile not return on linux?

我是 java 的新手,正在尝试使用 RandomAccessFile 读写命名管道(在另一个本机 C++ 进程中创建)。这是我的代码:-

String input_pipe = "/home/user/some_pipe";
try {
  System.out.println("here1");
  RandomAccessFile inp_pipe = new RandomAccessFile(input_pipe, "r");
  System.out.println("here2");
} catch (Exception exp) {
  System.out.println("Some error opening pipe :- " + exp.getMessage());
}

当我 运行 这段代码时,我得到的输出是:-

here1

而且这个过程并没有 return。关于我做错了什么或如何调试它的任何提示?

none位评论者选择了写答案,我自己写一个。

问题是在 linux 上打开命名管道将阻塞,直到管道的另一端也被打开。可以非阻塞方式打开,也可以同时打开管道的两端。