Why I cannot read from files in java -


i have problems reading external files. when tried read in.nextdouble or in.nextint or on throws inputmismatchexception. in 1 case can read file - when use in.next().

import java.io.*; import java.util.*;  public class echo1 {     public static void main(string[] args) throws filenotfoundexception {         scanner input = new scanner(new file("numbers.odt"));         double sum = 0.0;         (int = 1; <= 5; i++) {             double next = input.nextdouble();             system.out.println("number " + + " = " + next);             sum += next;         }         system.out.println("sum = " + sum);     } } 

this problem file format. code works .txt format. created "numbers.odt" file. didn't work. created "numbers.txt" file. worked. changed "numbers.txt" file's name "numbers.odt". worked.

"numbers.txt" contain: 1 2 3 4 5

you should learn how can read odt file java.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -