//工具包 log4j ,可以完成日志信息的建立
import java.io.*;
import java.util.*;
import java.text.*;
class ExceptionInfo
{
public static void main(String[] args) throws IOException
{
try
{
int[] arr = new int[2];
System.out.println(arr[3]);
}
catch (Exception e)
{
try
{
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s = sdf.format(d);
PrintStream ps = new PrintStream("exception.log");
ps.println(s);
//ps.write(d.toString().getBytes());//字节流对象操作(字符转的字节)
System.setOut(ps);
}
catch (Exception ex)
{
throw new RuntimeException("日志文件创建失败");
}
e.printStackTrace(System.out);//目的默认控制台
}
}
}
import java.io.*;
import java.util.*;
import java.text.*;
class ExceptionInfo
{
public static void main(String[] args) throws IOException
{
try
{
int[] arr = new int[2];
System.out.println(arr[3]);
}
catch (Exception e)
{
try
{
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s = sdf.format(d);
PrintStream ps = new PrintStream("exception.log");
ps.println(s);
//ps.write(d.toString().getBytes());//字节流对象操作(字符转的字节)
System.setOut(ps);
}
catch (Exception ex)
{
throw new RuntimeException("日志文件创建失败");
}
e.printStackTrace(System.out);//目的默认控制台
}
}
}