Get Installed Printer List using Java, Print a file with default Printer

Sharing is Caring

This post shows that how can we get installed printer list using PrintServiceLookup class

Implementations of this class provide lookup services for print services

package client;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

public class GetInstalledPrinters {

public static void main(String[] args) {
String defPrinter;

PrintService[] printService = PrintServiceLookup.lookupPrintServices(null, null);

System.out.println(“List of Installed Printers- “);
for (int i = 0; i < printService.length; i++) {
String printerName = printService[i].getName();
System.out.println(i + 1 + “. “ + printerName);

defPrinter = PrintServiceLookup.lookupDefaultPrintService().getName();
System.out.println(“nDefault Printer Name – “ + defPrinter);

Print File with Default Printer-

package client;

import java.awt.Desktop;


public class DesktopPrint {
public DesktopPrint() {
public static void main(String[] args) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.print(new File(“D:/Export.txt”));
} catch (IOException e) {

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Get Installed Printer List using Java, Print a file with default Printer”

  1. it is this code can get list printer from the client pc? i make java web n deploy it on linux server, when run this code it list printer on the server not the client pc. how can i get list printer from client pc?

Leave a Reply

Your email address will not be published. Required fields are marked *