How do you print out the output in Java Eclipse?

I need to physically print out my output box (using a printer) for a class.

Can someone please explain to me how to do this?

0

1 Answer

Instead of printing the console from eclipse, you can output all your System.out.println() directly to a file. Basically, you are using the file as a debugger instead of the console window. To do this, you can use the code below.

import java.io.*;
PrintWriter writer = new PrintWriter("debuggerOutput.txt", "UTF-8");
//in your class constructor, you will need to add some exception throws
write.println("I used to be in the debugger, but now I go in the file!!")

For each System.out.println(), add an extra write.println() with the same thing in the parenthesis so it outputs to the file what goes in the console. Then, you will see all your output in a file that you can easily print. At the end, make sure to write.close()

Full code:

import java.io.*;
public class test { public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException { PrintWriter writer = new PrintWriter("myFile.txt", "UTF-8"); writer.println("The line"); writer.close(); }
}
6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like