Solved

To connect a printer

Posted on 1997-12-16
1
399 Views
Last Modified: 2011-10-03
How to print a report in a printer through a java program
0
Comment
Question by:geostp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

696 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