Just a little change:
int count = 0;
int average = 0;
File file = new File("dvorak.txt");
Scanner inputFile = new Scanner(file);
if (!file.exists())
{
System.out.println("No file");
System.exit(0);
}
int totalLength = 0;
int lineCount = 0;
while(inputFile.hasNext())
{
String text = inputFile.nextLine();
lineCount += 1;
totalLength += text.length();
}
average = totalLength / lineCount;
System.out.println(average);
That should do the trick. You count all the line lengths in the file and then divide by the number of lines collected.
Regards,
Manfred