当尝试从中读取 input_events 时,/dev/input/event16
我注意到我正在读取的缓冲区的大小可能会导致异常。这是我写的代码:
public static void main(String[] args) throws IOException{
FileInputStream is = new FileInputStream("/dev/input/event16");
byte[] three_bytes = new byte[3];
byte[] twentyfour_bytes = new byte[24];
is.read(three_bytes); // fails
is.read(twentyfour_bytes); // does not fail
}
我最初的实验表明,缓冲区至少需要一个完整input_event
结构的容量。但我找不到原因。
问题是该行is.read(three_bytes);
导致以下异常:
Exception in thread "main" java.io.IOException: Invalid argument
at java.base/java.io.FileInputStream.readBytes(Native Method)
at java.base/java.io.FileInputStream.read(FileInputStream.java:249)
at main.Test.main(Test.java:11)
我想弄清楚为什么该行在按预期读取数据 is.read(three_bytes);
时抛出异常is.read(twentyfour_bytes);