Jump to Real's How-to Main page

Print text to a printer easily

A quick and simple way to output some text to a printer is to print to OS logical device attached a printer. For example, on a Windows machine :
import java.io.*;
public class SimplePrinting {
  public static void main(String[] args) {
    try {
      FileWriter out = new FileWriter("lpt1");
      out.write("Hello world");
      out.write(0x0D); // CR
      out.close();
      }
    catch (IOException e) {
      e.printStackTrace();
      }
    }
}

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]