title: How do I write the exception from printStackTrace() into a text file in Java?
body: <p>I need to capture the exception in a text file in Java.  For example: </p>
  
  <pre><code>try {
    File f = new File("");
  }
  catch(FileNotFoundException f) {
    f.printStackTrace();  // instead of printing into console it should write into a text file    
    writePrintStackTrace(f.getMessage()); // this is my own method where I store f.getMessage() into a text file.
  }
  </code></pre>
  
  <p>Using <code>getMessage()</code> works, but it only shows the error message.  I want all the information in the <code>printStackTrace()</code> including line numbers.</p>