<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to redirect console output to file using Java?</title>
	<atom:link href="http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/</link>
	<description>Digital compendium</description>
	<lastBuildDate>Sun, 15 Jan 2012 09:28:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Rituparna</title>
		<link>http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/comment-page-1/#comment-85169</link>
		<dc:creator>Rituparna</dc:creator>
		<pubDate>Mon, 12 Dec 2011 09:06:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/#comment-85169</guid>
		<description>I have done as commented by Mari. I am getting reuired output in out.txt file.All is Ok except that I want to view the same output in console also, that is output in both Console and out.txt file. But I am getting no output printed in console.</description>
		<content:encoded><![CDATA[<p><div class="KonaBody">I have done as commented by Mari. I am getting reuired output in out.txt file.All is Ok except that I want to view the same output in console also, that is output in both Console and out.txt file. But I am getting no output printed in console.</div><p></f</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mari</title>
		<link>http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/comment-page-1/#comment-69896</link>
		<dc:creator>Mari</dc:creator>
		<pubDate>Fri, 03 Jun 2011 23:41:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/#comment-69896</guid>
		<description>Hello, 

Just add the code in the main class 
, just after the declaration of main method 
every line of your original code within the &quot;try&quot; block.

PrintStream orgStream 	= null;
		PrintStream fileStream 	= null;
		try
		{
			// Saving the orginal stream
			orgStream = System.out;
			fileStream = new PrintStream(new FileOutputStream(&quot;out.txt&quot;,true));
			// Redirecting console output to file
			System.setOut(fileStream);
			// Redirecting runtime exceptions to file
			System.setErr(fileStream);

// Here all your original code

			throw new Exception(&quot;Test Exception&quot;);
 
		}
		catch (FileNotFoundException fnfEx)
		{
			System.out.println(&quot;Error in IO Redirection&quot;);
			fnfEx.printStackTrace();
		}
		catch (Exception ex)
		{
			//Gets printed in the file
			System.out.println(&quot;Redirecting output &amp; exceptions to file&quot;);
			ex.printStackTrace();
		}
		finally
		{
			//Restoring back to console
			System.setOut(orgStream);
			//Gets printed in the console
			System.out.println(&quot;Redirecting file output back to console&quot;);
 
		}

Thank you very much, this code helped me a lot.</description>
		<content:encoded><![CDATA[<p><div class="KonaBody">Hello, </p><p>Just add the code in the main class<br />, just after the declaration of main method<br />every line of your original code within the &#8220;try&#8221; block.</p><p>PrintStream orgStream 	= null;<br />		PrintStream fileStream 	= null;<br />		try<br />		{<br />			// Saving the orginal stream<br />			orgStream = System.out;<br />			fileStream = new PrintStream(new FileOutputStream(&#8220;out.txt&#8221;,true));<br />			// Redirecting console output to file<br />			System.setOut(fileStream);<br />			// Redirecting runtime exceptions to file<br />			System.setErr(fileStream);</p><p>// Here all your original code</p><p>			throw new Exception(&#8220;Test Exception&#8221;);</p><p>		}<br />		catch (FileNotFoundException fnfEx)<br />		{<br />			System.out.println(&#8220;Error in IO Redirection&#8221;);<br />			fnfEx.printStackTrace();<br />		}<br />		catch (Exception ex)<br />		{<br />			//Gets printed in the file<br />			System.out.println(&#8220;Redirecting output &amp; exceptions to file&#8221;);<br />			ex.printStackTrace();<br />		}<br />		finally<br />		{<br />			//Restoring back to console<br />			System.setOut(orgStream);<br />			//Gets printed in the console<br />			System.out.println(&#8220;Redirecting file output back to console&#8221;);</p><p>		}</p><p>Thank you very much, this code helped me a lot.</p></div><p></f</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bella</title>
		<link>http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/comment-page-1/#comment-69770</link>
		<dc:creator>bella</dc:creator>
		<pubDate>Thu, 02 Jun 2011 09:20:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/#comment-69770</guid>
		<description>Unable to run this program. Package is out of bounds . Help out.</description>
		<content:encoded><![CDATA[<p><div class="KonaBody">Unable to run this program. Package is out of bounds . Help out.</div><p></f</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roshidah</title>
		<link>http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/comment-page-1/#comment-50386</link>
		<dc:creator>Roshidah</dc:creator>
		<pubDate>Wed, 03 Nov 2010 04:57:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/#comment-50386</guid>
		<description>Dear respected Sir/Madam,

I&#039;ve tried using the example, thanks, it worked but can&#039;t I view the &quot;out.txt&quot; file?</description>
		<content:encoded><![CDATA[<p><div class="KonaBody">Dear respected Sir/Madam,</p><p>I&#8217;ve tried using the example, thanks, it worked but can&#8217;t I view the &#8220;out.txt&#8221; file?</p></div><p></f</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/comment-page-1/#comment-45903</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Fri, 17 Sep 2010 21:09:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.digitalprank.org/how-to-redirect-console-output-to-file-using-java/#comment-45903</guid>
		<description>Thanks for the great example!  This was exactly what I was looking for...</description>
		<content:encoded><![CDATA[<p><div class="KonaBody">Thanks for the great example!  This was exactly what I was looking for&#8230;</div><p></f</p>
]]></content:encoded>
	</item>
</channel>
</rss>

