我想从文件目录加载图像文件。然后,我想将文件对象转换为字符串对象。不幸的是,我不断收到这个错误信息。我该如何解决它?为什么要继续接收java.io.FileNotFoundException:(访问被拒绝)错误?
java.io.FileNotFoundException: E:\workspace\sesaja\Images (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at test.Test1.main(Test1.java:29)
氏是我的整个代码
public class Test1 {
public static void main(String args[]){
String s = System.getProperty("user.dir") + System.getProperty("file.separator")+ "Images";
File f = new File (s);
FileInputStream fis = null;
String str = "";
try {
fis = new FileInputStream(f);
int content;
while ((content = fis.read()) != -1) {
// convert to char and display it
str += (char) content;
}
System.out.println("After reading file");
System.out.println(str);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
是E:\ workspace \ sesaja \映像文件或目录? –
@DavideLorenzoMARINO它是一个文件目录 – Belle
你想从目录中读取吗?这是一个dir不是文件 –