Java write the stacktrace of exception into text file

htt‮/:sp‬/www.lautturi.com
Java write the stacktrace of exception into text file
/**
 * @author lautturi.com 
 * Java example: java write stacktrace into file
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;

public class Lautturi {

	public static void main(String[] args) throws FileNotFoundException {

		try {
			int a = 20/0;
		}
		catch (Exception e) {
			
			PrintWriter pw = new PrintWriter(new File("error.log"));
		    e.printStackTrace(pw);
		    pw.close();
		}
		
	}
}
Created Time:2017-09-27 20:35:54  Author:lautturi