How to check Printer is connected or not to your PC by Java?

前端 未结 4 1997
野的像风
野的像风 2021-01-27 06:19

I am able to get the name of printer which I had installed previously on my PC.But now its not physically connected to my pc. How should I check it first before moving to Print(

4条回答
  •  半阙折子戏
    2021-01-27 07:18

    You can use PrinterState attribute if it is supported by your printer.

    Something like this:

    PrintServiceAttributeSet printServiceAttributes = selectedService.getAttributes();
    PrinterState printerState = (PrinterState) printServiceAttributes.get(PrinterState.class);
           if (printerState != null){
              System.out.println(printerName + " is online");
           } 
           else {
              System.out.println(printerName + " is offline");
           }
    

提交回复
热议问题