An easy way to print to a specific printer that you select in the printdialog dialog box:
JEditorPane text = new JEditorPane("file:///D:/abc.txt");
text.print(null, null, true, null, null, false);
Printing on a default printer without printdialog:
JEditorPane text = new JEditorPane("file:///D:/abc.txt");
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
text.print(null, null, false, service, null, false);
source
share