• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do u print the error to a file

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hii


we have System.err to print to the cosole how do i redirect this to a file
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic