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 送离职同事简短祝福语