即使我在我聲明的確切目錄中有文件,FileNotFound異常仍在引發我的代碼。我也試過...new File("euler8.txt");...
沒有成功。我的代碼如下:正在拋出Java Filenotfound異常
private static void euler8() throws IOException
{
int current;
int largest=0;
int c =0;
ArrayList<Integer> bar = new ArrayList<Integer>(0);
File infile = new File("C:/Users/xxxxxxxx/workspace/Euler1/euler8.txt");
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(infile),
Charset.forName("UTF-8")));
try
{
while((c = reader.read()) != -1)
{
bar.add(c);
}
}
finally{reader.close();}
for(int i=0; i<bar.size(); i++)
{
current = bar.get(i) * bar.get(i+1) * bar.get(i+2) * bar.get(i+3) * bar.get(i+4);
if(largest<current)
largest = current;
}
}
的它是做什麼圖片:
http://img163.imageshack.us/img163/7017/halpbk.png
您是否嘗試過打印文件的絕對路徑,並可能將該輸出與新文件(「。」)的絕對路徑進行比較,以查看路徑中是否出現錯誤?文件名中是否正確? –
嘗試在聲明'infile'後立即添加'System.out.println(infile.exists());'。如果返回false,則文件路徑出現問題 - 繼續返回目錄,直至您成爲true。如果它真的回來...... –
嘗試使用'../ Euler1/euler8.txt'作爲文件路徑。 – Smit