Solved

To connect a printer

Posted on 1997-12-16
1
395 Views
Last Modified: 2011-10-03
How to print a report in a printer through a java program
0
Comment
Question by:geostp
1 Comment
 
LVL 6

Accepted Solution

by:
jpk041897 earned 0 total points
ID: 1231661
To print to a printer, you can open a file which name is the printer device. For example, suppose that your local
     laser printer device is "lpt1", you can do it like this:

     private void print(String report)
         {  
           if (report != "") {
         
           PrintWriter out = null;
            try {
              out = new PrintWriter(new BufferedWriter(new FileWriter("lpt1")));
            } catch ( IOException e) {};
         
          System.out.println("Report to be printed is : " + report);
           out.print(report);
           out.flush();
           out.close();
           }

     This code works well. If your printer device is LAN printer, you type command " net use lpt1 [the printer].
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 104
topping2 challenge 13 89
eclipse argument 14 60
varialbe initialization 11 32
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now