蜗牛―Java基础之学习(五)

2014-11-24 00:41:46 · 作者: · 浏览: 0

一、异常、自己定义了一个异常、

1、运行时异常:可以自己用逻辑代码进行控制、直接父类是RuntimeExpection

2、检查时异常:必须try-catch块、直接父类是Expection

日志:

Logger

log4j.rootLogger=debug,logfile,stdout
1、输出级别
2、介质名称
3、标准输出、向两个介质输出

	public static void deleteFile(File file) throws FileOperationExpection {
		Logger logger = Logger.getLogger(FileIoUtil.class);

		if (!file.exists())
			throw new FileOperationExpection("文件不存在");
		if (file.isDirectory())
			throw new FileOperationExpection("不是文件");
		logger.debug("执行删除" + file.getName() + "文件");
		file.delete();
	}

	public static void main(String[] args) {
		try {
			FileIoUtil.deleteFile(new File("G:\\t.txt"));
		} catch (FileOperationExpection e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}