JAVA获取系统默认打印机
是否可以使用Java打印服务API获取默认系统打印机 我可以使用JAVA获取系统默认打印机,java,printing,Java,Printing,是否可以使用Java打印服务API获取默认系统打印机 我可以使用 PrintServiceLookup.lookupPrintServices(null, null) 但如何在系统中选择打印机作为默认打印机?(在下面的屏幕截图中,选中默认打印机(HP Laser Jet)) 您可以使用 你应该使用 根据Javadocs: lookupDefaultPrintService查找此环境的默认打印服务。这可能返回null。如果多个查找服务都指定了一个默认值,则所选服务不会精确定义,但通常会返回一个平
PrintServiceLookup.lookupPrintServices(null, null)
但如何在系统中选择打印机作为默认打印机?(在下面的屏幕截图中,选中默认打印机(HP Laser Jet))
您可以使用
你应该使用
根据Javadocs:
lookupDefaultPrintService查找此环境的默认打印服务。这可能返回null。如果多个查找服务都指定了一个默认值,则所选服务不会精确定义,但通常会返回一个平台本机服务,而不是已安装的服务作为默认值。如果没有可明确识别的平台本机默认打印服务,则默认打印服务是第一个以依赖于实现的方式定位的打印服务
PrintService service =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service =
PrintServiceLookup.lookupDefaultPrintService();
if (service != null) {
String printServiceName = service.getName();
System.out.println("Print Service Name is " + printServiceName);
} else {
System.out.println("No default print service found");
}
import javax.print.PrintServiceLookup;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();