最近在网上查了一下,用java实现了打印机打印以及打印机开钱箱功能。

代码如下:

String os = System.getProperty("os.name");

if(os.contains("Windows")){

//Windows

try {

PrintWriter pw = new PrintWriter("lpt1");

//普通打印

pw.write("English-Windows"+"\n");

pw.write("中文-Windows"+"\n");

//打印机开钱箱指令

char[] c = {27,'p',0,60,240};

pw.write(c);

pw.write("\n");

pw.flush();

} catch (FileNotFoundException ex) {

Logger.getLogger(PrintTest.class.getName()).log(Level.SEVERE, null, ex);

}

}else{

//Linux

try {

FileOutputStream fos = new FileOutputStream("/dev/lp0");

//普通打印

fos.write("English-Linux\n".getBytes());

fos.write("中文-Linux\n".getBytes("GBK"));

//打印机开钱箱指令

char[] c = {27,'p',0,60,240};

for(int i=0;i

fos.write(c[i]);

}

fos.write("\n".getBytes());

fos.flush();

} catch (IOException ex) {

Logger.getLogger(PrintTest.class.getName()).log(Level.SEVERE, null, ex);

}

}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐