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