I'm was wondering if someone can check if this method produce the right result?
public int fileSize (String name) throws IOException
{
int charLength = 0;
File file = new File("name");
Scanner input = new Scanner(file);
while (input.hasNext()) {
charLength++;
}
return charLength;
}
What this is supposed to do is count the number of characters in the file whose name is supplied as the name parameter. The method return the number of characters in the file or -1 if an IOException occurs.
I'm not on my computer so i can't test it with the application.