1.程序员经常会关闭文件。JDK 7提供了下面的新的try-with-resources语法来自动关闭文件.
try(声明和创建资源){
使用资源文件;
}
public class TaskPrintWriter {
public static void main(String[] args) throws FileNotFoundException {
File file=new File("E:\\360MoveData\\Users\\黄大山\\Desktop\\1.txt");
//try-with-resources语法
try (PrintWriter output=new PrintWriter(file)){
output.println("你好啊:皇!");
output.println("小德子,退下");
}
}
}