• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do u print the error to a file  RSS feed

 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii


we have System.err to print to the cosole how do i redirect this to a file
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anil Verghese:
we have System.err to print to the cosole how do i redirect this to a file


From a java application, you can call System.seterr() with a new printstream that routes to a file.

From the command line, shell scripts, or batch files, you can use "2>filename" to route the errout to a file, in most cases. See the documentation on the command shell that you are using.

Henry
 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you can redirect your output error to a file by following way
import java.io.PrintStream;
import java.io.FileOutputStream;

class errRedirect
{
public static void main(String arg[])
{
System.setErr(new PrintStream(new FileOutputStream("c:\error.txt",true).false));
System.err.println("Hello this is the Error.txt file");
}
}

when you runs this program the output give to the err will be caputered in the error.txt file


Warm Regards
Pankaj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!