Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How To Redirect Standard Out

Posted on 1999-06-21
6
Medium Priority
?
288 Views
Last Modified: 2008-02-01
I would like to be able to redirect standard out in Java 1.1 to write directly to my local printer.

I would like to be able to do something like:

System.out.println( sMyStringToThePrinter );

and have it go to my printer.

Can this be done?  If so, how?  Could someone show me an example?  I don't know where to start.

0
Comment
Question by:Steve34
[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
  • 4
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 400 total points
ID: 1244248
Yes, use System´s Set Out method.

setOut

public static void setOut(PrintStream out)


Reassigns the "standard" output stream.

First, if there is a security manager, its checkPermission method is called with a RuntimePermission("setIO") permission to see if it's ok to reassign the "standard" output stream.

Parameters:

out - the new standard output stream.

Throws:

SecurityException - if a security manager exists and its checkPermission method doesn't allow reassigning of the standard output stream.

Since:

JDK1.1

See Also:

SecurityManager.checkPermission(java.security.Permission), RuntimePermission
0
 

Author Comment

by:Steve34
ID: 1244249
I got some of that from the docs, but what would an implementation of it look like?
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1244250
Something in the lines of:

System.setOut(new PrintStream(new FileOutputStream("LPT1:")));

Change LPT1: to whatever port (LPTx:) your priter is hooked on to.

Note: Depending on weather you are using an applet or an application, some security restriction may apply. C.F. FileOutputStream for additional info.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:jpk041897
ID: 1244251
You might also want to read the current open question at:

http://www.experts-exchange.com/Computers/Programming/Languages/Java/Q.10165426

for some additional insight.
0
 

Author Comment

by:Steve34
ID: 1244252
This is what I tried and I got an exception.  Any ideas what I am missing?  I actually do have a printer with a port of lpt1:

import java.util.*;
import java.text.*;
import java.lang.*;
import java.io.*;

public class HelloWorld
{
     public static void main( String[] args )
     {

      String sUnderlinedString = "I am underlined \r_______________";
 
      try
      {
                System.setOut(new PrintStream(new FileOutputStream("LPT1:")));
                System.out.print(sUnderlinedString);      
      }
      catch(IOException e)
      {
          System.err.println("IOException ");
      }  
      
     }// end main

}

0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1244253
Try changing LPT1: to PRN: wich redirects to the default printer.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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…
Suggested Courses

670 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