针对这个问题我想了好久才明白,原来是因为在调用方法的时候,方法内部的语句会抛出一个异常,所以必须得去处理,就拿今天学的一个方法举例:
方法:
[Java] 纯文本查看 复制代码 new File("a.txt").createNewFile();
源码:
[AppleScript] 纯文本查看 复制代码 public boolean createNewFile() throws IOException {
SecurityManager security = System.getSecurityManager();
if (security != null) security.checkWrite(path);
if (isInvalid()) {
throw new IOException("Invalid file path");
}
return fs.createFileExclusively(path);
}
看吧,点进去就看得清清楚楚的,有时候看源码还真是有用,即使看不懂 |