I need to capture the exception in a text file in Java. For example:
try { File f = new File(\"\"); } catch(FileNotFoundException f) { f.printStackTrac
It accepts a PrintStream as a parameter; see the documentation.
PrintStream
File file = new File("test.log"); PrintStream ps = new PrintStream(file); try { // something } catch (Exception ex) { ex.printStackTrace(ps); } ps.close();
See also Difference between printStackTrace() and toString()