• Post Reply Bookmark Topic Watch Topic
  • New Topic

print .txt file  RSS feed

 
sourav das
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print a .txt file within a java programe.

i have found a code to print a .gif file from horstmann book
import java.io.*;
import javax.print.*;

public class Print
{
public static void main(String[] args) {

try {

FileInputStream in = new FileInputStream("a.gif");
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
Doc doc = new SimpleDoc(in, flavor, null);
PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
DocPrintJob job = services[0].createPrintJob();
job.print(doc, null);

} catch (Exception e) { }
}
}

can anyone help to print a .txt file saved in the harddisk?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried any of the DocFlavor.INPUT_STREAM.TEXT... flavors? I would think that the rest of the code probably works unchanged.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!