• Post Reply Bookmark Topic Watch Topic
  • New Topic

print a file example.txt  RSS feed

 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file saved on my desktop. It is example.txt. I would like to print this file. I would like to get a hard copy.

Who can help me to write such a method?

public void printAFile() {

some code goes here

}

I thought, I might come from the package javax.print?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an example of printing a file here. The example uses a GIF file, but it's pretty obvious how the code needs to be changed to deal with text files. Note that this works only for those select few file formats the JDK and your printer understand; anything more complex (like HTML) needs special handling (which gets much more complicated).
 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I could compile the code, but nothing happens.

I changed TEXT_PLAIN_US_ASCII to AUTOSENSE. Although it does not work. I found this idea here:

http://forum.java.sun.com/thread.jspa?threadID=264594&messageID=1002035

Hmm...strange. I do not have success.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!