Java的.获取系统默认打印机

MyT*_*tle 1 java printing

可以使用Java Print Service API获取默认系统打印机吗?

我可以获得所有打印机的列表

PrintServiceLookup.lookupPrintServices(null, null)
Run Code Online (Sandbox Code Playgroud)

但如何在系统中选择默认的打印机?(在下面的屏幕截图中,选中默认打印机(HP Laser Jet)).

选择默认打印机

Azo*_*ous 10

你应该用 PrintServiceLookup

import javax.print.PrintServiceLookup;
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); 
Run Code Online (Sandbox Code Playgroud)

加.到Javadocs:

lookupDefaultPrintService查找此环境的默认打印服务.这可能会返回null.如果多个查找服务均指定了默认值,则未精确定义所选服务,但通常会返回平台本机服务而非已安装服务作为默认值.如果没有可清楚识别的平台本机默认打印服务,则默认是第一个以依赖于实现的方式定位.