Scoopta Scoopta - 2 months ago 19
Java Question

Reading /dev/input/js0 from Java

I'm trying to read

/dev/input/js0
from Java but I keep getting

java.io.IOException: Invalid argument
at java.io.FileInputStream.read0(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:207)
at Test.main(Test.java:7)


My code is

import java.io.*;

final class Test {
public static final void main(String[] args) {
try {
FileInputStream in = new FileInputStream("/dev/input/js0");
System.out.println(in.read());
} catch(IOException e) {
e.printStackTrace();
}
}
}


My end goal is to be able to read input from my controller but I can't even seem to read one byte. What am I doing wrong? My user does have read and write access to the file.

Answer

Changing the FileInputStream to a BufferedInputStream seems to fix the issue.