Use string.toCharArray(), something like:
while (scan.hasNext()) {
String line = scan.nextLine();
numberchars += line.toCharArray().length;
// ...
}
An Alternative would be to use directly the string.length:
while (scan.hasNext()) {
String line = scan.nextLine();
numberchars += line.length;
// ...
}
Using the BfferedReader you can do it like this:
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(file), charsetName));
int charCount = 0;
while (reader.read() > -1) {
charCount++;
}