Java如何获得默认的打印服务(打印机)?
要查找默认的打印服务,我们可以使用javax.print.PrintServiceLookupclasslookupDefaultPrintService()方法。
package org.nhooo.example.print;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class GetPrinter {
public static void main(String[] args) {
//获取此环境的默认打印服务。当返回null
// 找不到默认的打印服务。
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
if (service != null) {
String printServiceName = service.getName();
System.out.println("Print Service Name = " + printServiceName);
} else {
System.out.println("No default print service found.");
}
}
}上面的代码片段的结果:
Print Service Name = HP LaserJet P1005
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短