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.

1 Answer

Wrapping the FileInputStream in a BufferedInputStream seems to fix the issue.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.