java中的命名管道
我编写了一个java应用程序,它可以操作由另一个程序创建的文件。我希望我的程序能够实时工作,为此,我需要在另一个程序写入文件时读取文件。 简单的解决方案是即使在无限循环中达到 EOF 也继续从文件中读取,但这非常低效。
更好的解决方案是使用命名管道并将程序配置为写入该管道(我可以选择程序的输出文件)。我对 Windows 中的管道一无所知,也不知道如何在文件系统中创建它们。如果可能的话,我想从我的应用程序(用java)创建它们,但任何其他方式也很好。
我正在 Windows XP SP3 中工作。
在 Windows 中甚至可能吗?最好的方法是什么?
谢谢, 雅奈
I have written a java app which manipultes a file which is created by another program. i want my program to work in real time, in order to do so, i need to read from a file while the other program is writing it.
the simple solution is to keep reading from the file even when EOF has been reached in an infinite loop, but thats very ineffecient.
the better solution is to use a named pipe and configure the program to write to that pipe (i can choose the output file of the program). I know nothing about pipes in windows and i have no idea how to create them in the filesystem. if possible, i would like to create them from my app (in java), but any other way will be good as well.
i am working in windows xp SP3.
is it even possible in windows? and what is the best way?
thanks,
Yannay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然 Windows 有管道,但它们与 *nix 下的管道并不完全相同(请参阅此维基百科页面) 并且 Java 中不支持。常见的建议是使用套接字进行进程间通信。虽然我无法提供任何确凿的证据,但如果您通过本地主机运行,与管道相比,这不会产生大量开销,并且如果您稍后选择在不同的计算机上运行进程,也将使您的代码更加灵活。
While windows has pipes they aren't completely the same as those under *nix (see this wikipedia page) and there is no support in Java. The common suggestion is instead to use a socket for interprocess communication. Though I can not provide any hard evidence, if you are running through the localhost this should not create a significant amount of overhead versus a pipe, and will also allow your code to be more flexible if you later choose to run the processes on different machines.