Check out example codes for "java print stacktrace to file". It will help you in understanding the concepts better.

Code Example 1

//printStackTrace() can accept PrintWriter or PrintStream as argument
catch (Exception e) {

    PrintWriter pw = new PrintWriter(new File("file.txt"));
    e.printStackTrace(pw);
    pw.close();
}

/*Credits: 
Stackoverflow Users: 
Less (https://stackoverflow.com/users/587318/less)
Qnan (https://stackoverflow.com/users/190670/qnan)*/

Learn ReactJs, React Native from akashmittal.com