Following is the code when I run on Linux,detects my printer and gives me print out.but when I run it on windows.It do not detect my printer.
printbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DocFlavor docflavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
attr_set.add(new Copies(1));
PrintService[] service = PrintServiceLookup.lookupPrintServices(null, null);
if (service.length==0) {
JOptionPane.showMessageDialog(null, "No Printer Selected");
}
else if (service.length > 0) {
System.out.println("Selected printer is " + service[0].getName());
DocPrintJob pj = service[0].createPrintJob();
{
PrintService ps = pj.getPrintService();
FileInputStream fis = null;
try {
File file = new File("c:\\NewFile.txt");
fis = new FileInputStream(file);
Doc doc = new SimpleDoc(fis, docflavor, null);
pj.print(doc, attr_set);
} catch (PrintException ex) {
Logger.getLogger(PrintButtonView.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(PrintButtonView.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fis.close();
} catch (IOException ex) {
Logger.getLogger(PrintButtonView.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
});
}