PrintWrite
// 将此 throwable 及其追踪输出到指定的 PrintWriter
/*
异常处理将异常追踪输出到一个指定文件夹里面
//File(URI uri) 通过将给定的 file: URI 转换为一个抽象路径名来创建一个新的 File 实例.
File file=new File(URL); //里面是一个正确地路径
//PrintWriter(File file) //里面是一个文件路径
PrintWrite pw=new PrintWrite(file); //会抛出FileNotFoundException
e.printStackTrace(pw); //异常e调用printStackTrace将异常写入文件中
*/
package Exception.net;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ExceptionDome {
public static void main(String[] args) throws FileNotFoundException {
//将此 throwable 及其追踪输出到指定的 PrintWriter
File file = new File("E:\\workspace-2014\\20140924\\src\\Exception\\net\\a.txt");
PrintWriter pw = new PrintWriter(file);
int a[] = { 1, 2, 3 };
try {
System.out.println(a[4]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
e.printStackTrace(pw);
}
pw.flush();//立即写入
pw.close();//释放资源
}
}
*/
// 将此 throwable 及其追踪输出到指定的 PrintWriter
/*
异常处理将异常追踪输出到一个指定文件夹里面
//File(URI uri) 通过将给定的 file: URI 转换为一个抽象路径名来创建一个新的 File 实例.
File file=new File(URL); //里面是一个正确地路径
//PrintWriter(File file) //里面是一个文件路径
PrintWrite pw=new PrintWrite(file); //会抛出FileNotFoundException
e.printStackTrace(pw); //异常e调用printStackTrace将异常写入文件中
*/
一个小案例
package Exception.net;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ExceptionDome {
public static void main(String[] args) throws FileNotFoundException {
//将此 throwable 及其追踪输出到指定的 PrintWriter
File file = new File("E:\\workspace-2014\\20140924\\src\\Exception\\net\\a.txt");
PrintWriter pw = new PrintWriter(file);
int a[] = { 1, 2, 3 };
try {
System.out.println(a[4]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
e.printStackTrace(pw);
}
pw.flush();//立即写入
pw.close();//释放资源
}
}
*/