English 中文(简体)
采用 Java的灯管
原标题:Read/Write to linux Pipe using Java
  • 时间:2009-10-27 16:32:31
  •  标签:

我的问道是怎样才能阅读/写给 Java的灯塔管道? 我已经使用了java.io.RandomAccess。 档案

   RandomAccessFile file = new RandomAccessFile("/dev/zap/16", "rw");

并且随后将其传给工人读物,在每两条ms子之后读写

  byte[] buffer = new byte[16];
  file.read(buffer);

它从管道中读过,但我怀疑有些 by子是虚构的。 你们是否知道气味(ubuntu)是如何处理管道的缓冲?

问题回答

我过去曾尝试过这件事,但你的行为是错的。 林丹首先存在于——首先在定义上属于(FIFO)。 因此,你只能按照你撰写的同样顺序阅读,而不是随意阅读。 我建议使用一个正常的<代码>File,并处以罚款。

据我所知, Pipe以任何方式处理管道。 你只是向它提出书面文件。

你们可以真正地在管道中找到任何东西,因为你可以在管道中寻求。 出于同样的原因,<代码>RandomAccessFile >是选择使用(因为管道是明文的而不是随机取用文件)。 我建议使用<代码>FileOutputStre。

并请注意,在缓冲区完整之前,没有保证将<条码>改为>。 也可以读到一个单张,你需要检查其返回价值,并可能读到充分的缓冲。

I think you may not be flushing after writing, so do OutputStream.flush() often and read may be a byte at time, at least to see if your data is getting thru. e.g. to start with open a named pipe in readonly mode(FileInputStream) in process1, open it in write mode(FileOutputStream ) in process2, so anything you write in process2 will be read in process1.

页: 1

http://www.tldp.org/LDP/lpg/node15.html
http://www.unixguide.net/unix/programming/2.10.5.shtml http://www.unixguide.net/unix/programming/2.10.6.shtml





相关问题
热门标签