1//printStackTrace() can accept PrintWriter or PrintStream as argument
2catch (Exception e) {
3
4 PrintWriter pw = new PrintWriter(new File("file.txt"));
5 e.printStackTrace(pw);
6 pw.close();
7}
8
9/*Credits:
10Stackoverflow Users:
11Less (https://stackoverflow.com/users/587318/less)
12Qnan (https://stackoverflow.com/users/190670/qnan)*/