How to save console output to a file in Eclipse

Last updated on November 23, 2020 by Dan Nanni

When you are running/debugging an application in Eclipse, output or any logging information of your application is sent to the console. While you can check Eclipse console box for diagnosis and debugging, the Eclipse console can only preserves the last bit of program output/logs, not the entire history. So if your program generates a huge size of output/logs, you may want to save console output to a separate file for offline inspection. There are two ways of doing it.

The first method is to tell Eclipse to save console output to a file. For that, go to RunDebug Configurations on Eclipse menu. Then under Standard Input and Output section, click on checkbox next to File:, and choose the name of output file to use. If you check Append underneath, console output will be appended to the output file. Otherwise, console output will be overwritten to the file.

The other approach is to explicitly redirect console output to a file within your program itself. If your program is written in Java, you can add the following code at the beginning of your program.

System.setOut(new PrintStream(new FileOutputStream("output.txt")));
System.out.println("This is test output");

Then, all console output generated by System.out.* will be redirected to the output file.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean