If you mean print as on a "Printer" you need to look at the java.awt.print package. Printing in Java is somewhat complex... well actually printing is just complex anyway.
Here is a link to a good introduction article on the use of the print package:
i appreciate for your help, thanks. and i actually got a sample code from sun, which can work, i dont know why. i compiled the program, gave no error, but when i run it give no result.
suppose, i want the program to print the text file on a Printer.
import java.awt.*;
import java.io.*;
public class lpt
{
public static void main (String[] argv)
{
//check for argument
if (argv.length != 1)
{
System.out.println("usage: java lpt <printer name>"
System.exit(0);
}
try
{
//open printer as if it were a file
FileOutputStream os = new FileOutputStream(argv[0]);
//wrap stream in "friendly" PrintStream
PrintStream ps = new PrintStream(os);
//print text here
ps.println("Hello world!"
//form feed -- this is important
//Without the form feed, the text
//will simply sit in the print
//buffer until something else
//gets printed.
ps.print("\f"
//flush buffer and close
ps.close();
}
catch (Exception e)
{
System.out.println("Exception occurred: " + e);
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.