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.

1 Answer

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

2

Your Answer

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.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest