JAVA中Required type: AutoCloseable Provided: File错误

InputStreamReader isr = new InputStreamReader(new FileInputStream("G:\\IO流文件\\student2018.txt"));  //这个样子写就不报错
File f1= new File("G:\\IO流文件\\student2018.txt");     //这里就报错了    Required type: AutoCloseable  Provided: File
            FileInputStream fis = new FileInputStream(f1);
            InputStreamReader isr = new InputStreamReader(fis);

我寻思着这两个写法不一样吗,为什么第二种会报错?求指点

代码全一点呢?
你是不是在 try () 里面声明的变量?try里面声明的变量必须要 实现 AutoCloseable 接口。

你 new File() 就不要声明变量了,作为临时对象就行。