gpt4 book ai didi

Java Filenotfound 异常被抛出

转载 作者:行者123 更新时间:2023-12-01 07:34:27 25 4
gpt4 key购买 nike

即使我的文件位于我指定的确切目录中,我的代码也会引发 FileNotFound 异常。我也尝试过 ...new File("euler8.txt");... 但没有成功。我的代码如下:

        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

最佳答案

除了建议的其他内容之外,您可以检查是否遇到此问题(我们在实验室中已经看到过):文件扩展名是两倍。换句话说,请确保您的 euler8.txt 确实被称为该名称,而不是 euler8.txt.txt,因为,使用隐藏的扩展名,文件资源管理器将显示第一个,但如果您不记得它应该隐藏扩展名,那么一开始您可能不会觉得奇怪。

关于Java Filenotfound 异常被抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13962348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com