Java: use NIO with System.in [duplicate]

柔情痞子 提交于 2019-12-04 07:40:11
Jason S

duplicate:

How to get SelectableChannel from an InputStream?

hmmm... on second thought, for stdin there may be a solution. I found this reference:

http://www.javafaq.nu/java-example-code-346.html

and in particular:

SystemInPipe.java (class which encapsulates stdin as a selectable channel)

I don't know about a SelectableChannel, but you can convert an InputStream to a ReadableByteChannel with

using java.nio.channels.Channels;

...

ReadableByteChannel in = Channels.newChannel(System.in);

You could create a Pipe and a custom thread to read from standard input and write to the pipe.

Once you have the Pipe you can then get the input channel.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!