Java 如何获取已安装打印机的列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/410967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:18:20  来源:igfitidea点击:

How do I get a list of installed printers?

java

提问by Thomas Zuberbühler

I'm searching for a possibility to get a list of installed printers. I'm using JDK 1.6 with a Windows operating system. Does anyone know a solution?

我正在寻找获取已安装打印机列表的可能性。我在 Windows 操作系统上使用 JDK 1.6。有谁知道解决方案?

Thank you in advance.

先感谢您。

采纳答案by Pedro Henriques

Just wanted to add a little snippet:

只是想添加一个小片段:

import javax.print.*;

class Test {

    public static void main (String [] args)
    {
        PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
        System.out.println("Number of print services: " + printServices.length);

        for (PrintService printer : printServices)
            System.out.println("Printer: " + printer.getName()); 
    }
}

回答by Ronald Blaschke

I haven't used this myself, but maybe javax.print.PrintServiceLookupcontains what you are looking for.

我自己没有使用过这个,但可能javax.print.PrintServiceLookup包含您正在寻找的内容。

回答by alain

Update for the newer Java packages

更新较新的 Java 包

just modify:

只需修改:

import javax.print.PrintService;

import javax.print.PrintServiceLookup;