当前位置:我的异常网» 热门搜索 » 开钱箱

开钱箱

www.MyException.Cn  网友分享于:2020-05-27   搜索量:244次
场景:java 打印机打印跟开钱箱

java 打印机打印和开钱箱

最近在网上查了一下,用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<c.length;i++){
??????????????????? fos.write(c[i]);
??????????????? }
??????????????? fos.write("\n".getBytes());
??????????????? fos.flush();
??????????? } catch (IOException ex) {
??????????????? Logger.getLogger(PrintTest.class.getName()).log(Level.SEVERE, null, ex);
??????????? }
??????? }

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有

九色优选 | 跳跳猪 | 聚聚玩 | 有赚网 | 聚享游 | 快乐赚