Unable to write to file LPT1 java

499 views Asked by At

I have one small problem. Somewhere I found that I can program LPT port by writing to file "LPT1" But this code doesn't work. It outputs:

1

2

3

Here is my code:

public static void writeByte(byte data, String portName) throws IOException {
        System.out.println("1");
        FileOutputStream port = new FileOutputStream(portName);
        System.out.println("2");
        PrintStream printer = new PrintStream(port);
        System.out.println("3");
        printer.write(data);
        System.out.println("4");
        printer.println('\f');
        System.out.println("5");
        printer.flush();
        System.out.println("6");
        printer.close();
        System.out.println("7");
        port.close();
        System.out.println("8");
}
1

There are 1 answers

0
Michał Zaborowski On BEST ANSWER

Under Linux devices are files, that is why I've asked. Under Windows you need to have library and deal with that library. Type "Windows lpt port programming" into your favorite search engine. Here is sample solution.