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;)

[1497 byte] By [zokhoa] at [2007-10-3 4:39:28]
# 1
http://forum.java.sun.com/help.jspa?sec=formatting
CeciNEstPasUnProgrammeura at 2007-7-14 22:43:23 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi

I tried like this

public class MyJava

{

/**

* @param args

*/

public static void main(String[] args)

{

try

{

FileInputStream textStream;

textStream = new FileInputStream(

System.getProperty("user.home")+"/Desktop/errors.txt");

if (textStream == null)

{

System.exit(0);

}

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();

job.print(mydoc, aset);

}

} catch (Exception ee)

{

System.err.println(ee);

}

}

}

Its working fine.and printing.Check your file path .

Here System.getProperty("user.home") is replacement of C:/Documents and Settings/admin;

Thanks

smile

smile4ua at 2007-7-14 22:43:23 > top of Java-index,Java Essentials,Java Programming...