代码如下:
package file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class TestClose {
public static void main(String\[\] args) {
// TODO Auto-generated method stub
File fileInput = new File("/Users/apple/Desktop/Result");
File fileInput1 = new File("/Users/apple/Desktop/报销.xlsx");
try (FileInputStream fis = new FileInputStream(fileInput);
FileInputStream fis1 = new FileInputStream(fileInput1);) {
fis.read();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行时出错:
java.io.FileNotFoundException: /Users/apple/Desktop/Result (Is a directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at file.TestClose.main(TestClose.java:16)
但是不知道错在哪儿?有哪位大神可以指点一下?
Users/apple/Desktop/Result是一个文件夹吗?如果是,不能用FileInputStream 来读取,只有文件才能用FileInputStream 读取其内容。