My Program Won't Print when its supposed to
I've been trying to get a program that will automatically print txt files just by running it. Here's what I've come up with so far:
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
import java.awt.print.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.*;
import javax.*;
publicclass PrintTests8
{
publicstaticvoid main(String[] args)
{
try
{
// Open the text file
InputStream is =new BufferedInputStream(new FileInputStream("test.txt"));
// Find the default service
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc =new SimpleDoc(is, flavor,null);
// Print it
job.print(doc,null);
// It is now safe to close the input stream
is.close();
}
catch (PrintException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
This will print out the file, but the problem is that it will only print itwhen another job, printed using in the normal, Ctrl+P type way, is printed. I hope that I can get help from you guys on this.

