Solved

To connect a printer

Posted on 1997-12-16
1
392 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 38
triangle challenge 4 79
basic hardware to learn oop advanced design patterns 3 74
parentbit challenge 3 52
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

21 Experts available now in Live!

Get 1:1 Help Now