So we have this program where we have to read double values from a text file into a double ArrayList and make certain calculations.
example of the text file:
Note: there's space between the date and the double values
5/05/1998 4.4 1/01/1999 -4.123 the problem is that i'm getting is as below:
"NumberFormatException for input string: 1/2/1950 0.0258" error.
Here's my code:
public static void value() throws java.io.IOException{ try{ BufferedReader br = new BufferedReader(new FileReader(new File("SP500-Weekly.txt"))); ArrayList<Double>list = new ArrayList<Double>(); String line; while((line=br.readLine())!=null){ String[] r = line.split(" "); for(int i=0; i<r.length; i++){ double val = Double.parseDouble(r[i]); list.add(val); } }br.close(); System.out.println(list.size()); } catch(IOException io){ System.out.println("error"); } }