A FileNotFound Exception is being thrown for my code even though I have the file in the exact directory I stated. I have also tried ...new File("euler8.txt");... with no success. My code is as follows:
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;
}
}
Image of what it is doing:
Except for everything else that has been suggested, you could check whether you’re having this issue (which we’ve been seeing in our lab): Files with twice the extension. In other words, make sure your
euler8.txtis really called that and noteuler8.txt.txt, for instance, because, with hidden extensions, the file explorer will show the first but it may not strike you as odd initially, if you don’t remember that it’s supposed to hide the extension.