我可以使用NIO.2从Java中的键盘(/dev/tty)进行异步IO吗?

我可以使用NIO.2从Java中的键盘(/dev/tty)进行异步IO吗?,java,asynchronous,nio,Java,Asynchronous,Nio,我试图从/dev/tty使用NIO.2异步IO,但在以下代码中,读取不会阻塞: import java.io.*; import java.nio.*; import java.nio.channels.*; import java.nio.file.*; public class AsyncKbd { public static void main(String[] args) throws IOException { AsynchronousFileChannel

我试图从/dev/tty使用NIO.2异步IO,但在以下代码中,读取不会阻塞:

import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.file.*;

public class AsyncKbd {
    public static void main(String[] args) throws IOException {

        AsynchronousFileChannel kbd = AsynchronousFileChannel.open(Paths.get("/dev/tty"),
            StandardOpenOption.READ);

        CompletionHandler<Integer, ByteBuffer> handler = new   CompletionHandler<Integer, ByteBuffer>() {
            public void completed(Integer i, ByteBuffer buffer) {
                System.out.print(new String(buffer.array()));
            }

            public void failed(Throwable exc, ByteBuffer buffer) {
            }
        };

        ByteBuffer buffer = ByteBuffer.allocate(80);

        kbd.read(buffer, 0, buffer, handler);
    }
}
import java.io.*;
导入java.nio.*;
导入java.nio.channels.*;
导入java.nio.file.*;
公共类异步KBD{
公共静态void main(字符串[]args)引发IOException{
AsynchronousFileChannel kbd=AsynchronousFileChannel.open(path.get(“/dev/tty”),
标准OpenOption.READ);
CompletionHandler=新的CompletionHandler(){
公共无效已完成(整数i,字节缓冲区){
System.out.print(新字符串(buffer.array());
}
公共无效失败(可丢弃的exc、ByteBuffer缓冲区){
}
};
ByteBuffer缓冲区=ByteBuffer.allocate(80);
读(缓冲区,0,缓冲区,处理程序);
}
}
我怀疑由于/dev/tty是一个设备,所以文件位置参数(0)等于大小(suposedly也等于0),并且读取不会阻塞。那么如何从键盘编写异步读取+回调处理程序