我想從文件目錄加載圖像文件。然後,我想將文件對象轉換爲字符串對象。不幸的是,我不斷收到這個錯誤信息。我該如何解決它?爲什麼要繼續接收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不是文件 –