即使我在我所说的确切目录中有文件,也会为我的代码引发 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;
}
}
它在做什么的图像: