0

Hi ppl,

i am trying print a txt file from within my java code, here is the code i have done so far
but i am getting some runtime errors,

also i am trying to keep the coding to a minimum...any help would be appreciated,

--------------------------------------------------------------------------------------------------------
package AddRFSwitchPac;
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

public class Printing {
public static void main(String args[]) throws Exception {
String filename = ("D:/report"); // THIS IS THE FILE I WANT TO PRINT
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // MY FILE IS .txt TYPE
PrintService printService[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
System.exit(0);
}
}
--------------------------------------------------------------------------------------------------
As i said any help would be appreciated

thanks for your time, guys..

TC

2
Contributors
4
Replies
18
Views
9 Years
Discussion Span
Last Post by D boss
0

ok i have screen dumped the errors from dos window
and attached it to this reply...


See attachment...

cheers buddy..
tc

Attachments
0

You are getting the error because you defined the class to be in the "AddRFSwitchPac" and you are trying to run it with "java Printing". Use "java AddRFSwitchPac.Printing" instead. That is assuming you have the Printing class in a folder named "AddRFSwitchPac" and that you are trying to run it from the directory above "AddRFSwitchPac".

0

thank you matey,, that was great,,,, why did'nt I remember that..lol

thanks a bunch.. that really helped

tc

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.