I'm trying to create a method that adds to a variable for each character inside a file. If the file was:
abcd
abc
ab
then after the function ran the variable it would return would be equal to 9.
Here's the code I have so far:
public static double getRow(String filename) {
double size = 0;
File f;
Scanner infile;
try{
f = new File(filename);
infile = new Scanner(f);
}
catch (IOException e){
System.out.println("Error opening the file");
//System.exit(0); not good
}
while(infile.hasNext()) {
size++;
}
infile.close();
return size;
}
But I keep getting that infile
has not been initialized. I'm not sure how to get the solution I want.