我有个小问题。在某个地方,我发现我可以通过编写文件"LPT1“来编程LPT端口,但是这段代码不起作用。它的产出如下:
1 2 3.
这是我的代码:
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");
}发布于 2017-10-24 09:48:33
在Linux下,设备是文件,这就是我所问的原因。在Windows下,您需要拥有库并处理该库。在你最喜欢的搜索引擎中输入"Windows端口编程“。Here是样品溶液。
https://stackoverflow.com/questions/46873068
复制相似问题