打印没有问题,想要获取本地打印机状态或者异常状态,但是一直是空的
public static void checkPrinterStatus(PrintService printService) { try { // 获取打印机的状态原因属性 boolean attributeCategorySupported = printService.isAttributeCategorySupported(PrinterState.class); System.out.println(attributeCategorySupported); PrinterState attribute = printService.getAttribute(PrinterState.class); PrinterStateReasons reasOns= (PrinterStateReasons) printService.getAttribute(PrinterStateReasons.class); // 检查打印机是否缺纸 if (reasons.containsKey(MEDIA_NEEDED) || reasons.containsKey(PrinterStateReason.MEDIA_LOW)|| reasons.containsKey(PrinterStateReason.MEDIA_EMPTY)) { System.out.println("打印机缺纸!"); } // 检查打印机是否缺墨 if (reasons.containsKey(PrinterStateReason.TONER_LOW) || reasons.containsKey(PrinterStateReason.TONER_EMPTY)) { System.out.println("打印机缺墨!"); } // 其他状态检查... } catch (Exception e) { e.printStackTrace(); } }
谁有经验给看一下呗