print a txt file by a printer?!!
hi
i wanna print a simple document as a test.ive written these simple codes to do it but there r some problems!!!
take look at ma codes then i explain what happen exacly and what i really need to do:
try{
FileInputStream textStream;
textStream=new FileInputStream("C:/Documents and Settings/admin/Desktop/mytxt.txt");
if(textStream==null){
return;
}
DocFlavor flavor=DocFlavor.INPUT_STREAM.POSTSCRIPT;
Doc mydoc=new SimpleDoc(textStream,flavor,null);
PrintRequestAttributeSet aset=new HashPrintRequestAttributeSet();
aset.add(new Copies(2));
PrintService[]services=PrintServiceLookup.lookupPrintServices(flavor,aset);
System.out.println(services.length);
if(services.length>0){
DocPrintJob job=services[0].createPrintJob();
try{
job.print(mydoc,aset);
}catch(PrintException pe){System.err.println(pe);}
}
}catch(Exception ee){System.err.println(ee);}
//////////////////////////////////////////////////////////
ok i think ma problem is in the line that is bolded !!!
it prints "0" that means it couldnt find a printer?
by the way my platform is windows xp and my printer is shared on the network and ive got an instance of it incontrol panel/printer and fax
it actuly works perfect when im printing a document on ma system.
the printer model is: HP 1320 laserJet.
best regards ..............
zokho;)

