Steve34
asked on
How To Redirect Standard Out
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
You might also want to read the current open question at:
https://www.experts-exchange.com/Computers/Programming/Languages/Java/Q.10165426
for some additional insight.
https://www.experts-exchange.com/Computers/Programming/Languages/Java/Q.10165426
for some additional insight.
ASKER
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(sUnderlin edString);
}
catch(IOException e)
{
System.err.println("IOExce ption ");
}
}// end main
}
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(sUnderlin
}
catch(IOException e)
{
System.err.println("IOExce
}
}// end main
}
Try changing LPT1: to PRN: wich redirects to the default printer.
ASKER