I created a text file using java and saved it using this code:
BufferedWriter bfw;
bfw = new BufferedWriter(new FileWriter("D:\\abc.txt"));
Now I want to call the printer from my java code to print the file, how do I do this ?
I created a text file using java and saved it using this code:
BufferedWriter bfw;
bfw = new BufferedWriter(new FileWriter("D:\\abc.txt"));
Now I want to call the printer from my java code to print the file, how do I do this ?
Maybe look into an API that supports printing.
If you are using java 1.7 higher you can use this one. You can find an example inside the documentation.
http://docs.oracle.com/javase/7/docs/api/javax/print/package-summary.html
A simple way to print to a specific printer which you select in a printdialog:
JEditorPane text = new JEditorPane("file:///D:/abc.txt");
text.print(null, null, true, null, null, false);
To print to the default printer without printdialog:
JEditorPane text = new JEditorPane("file:///D:/abc.txt");
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
text.print(null, null, false, service, null, false);