我试图获取有关系统上打印机的一些信息。
在Windows和Linux,使用此代码,只有PrinterName
属性填充:Java中的扩展打印机信息
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null,null);
for(PrintService printService : printServices) {
log.info("Found print service: "+printService);
log.info(printService.getAttribute(PrinterName.class));
log.info(printService.getAttribute(PrinterLocation.class));
log.info(printService.getAttribute(PrinterMakeAndModel.class));
log.info(printService.getAttribute(PrinterMessageFromOperator.class));
log.info(printService.getAttribute(PrinterMoreInfo.class));
log.info(printService.getAttribute(PrinterMoreInfoManufacturer.class));
log.info(printService.getAttribute(PrinterState.class));
log.info(printService.getAttribute(PrinterStateReasons.class));
log.info(printService.getAttribute(PrinterURI.class));
}
使用就可以了toArray()
功能后...
log.info("Found print service: "+printService);
for(Attribute a : printService.getAttributes().toArray()) {
log.info("* "+a.getName()+": "+a);
}
...这就是结果:
Found print service: Win32 Printer : Brother MFC-9420CN BR-Script3 * color-supported: supported * printer-name: Brother MFC-9420CN BR-Script3 * printer-is-accepting-jobs: accepting-jobs * queued-job-count: 0
我如何获得更多的信息,像打印机ç omment?
如果您从'PrintService.getAttributes()'迭代返回,您会看到什么? – 2011-04-06 19:16:12
你不能遍历它。另外,我查看了Java Source并开始认为Java开发人员讨厌打印机。起初,他们构建了一个胖胖的API,然后他们自己也只是在Linux和Windows上用4个(!)〜20个可能的属性填充属性集。对不起,但这只是伤心。 – Daniel 2011-04-06 21:22:00
当然你可以 - 只使用超类型的'toArray'('AttributeSet')并迭代数组。 – 2011-04-07 00:17:03