I am trying to convert a list of numbers from a txt file into an array of numbers. There is 26 numbers, and each is on a different line in the text file. My code is
import java.io.*;
public class rocket {
public static void main(String[] args) throws IOException, FileNotFoundException
{
BufferedReader b = new BufferedReader(new InputStreamReader(new FileInputStream("/Users/Jeremy/Documents/workspace/altitude.txt")));
String[] stringArray = new String[25];
double[] doubleArray = new double[stringArray.length];
for(int i=0; i<25; i++)
{
stringArray[i] = b.readLine();
doubleArray[i] = Double.parseDouble(stringArray[i]);
}
for(int i = 0; i<doubleArray.length; i++)
{
System.out.println(doubleArray[i]);
}
}
}
But every time I run it I get a number format exception. And if I try to just print out the strings I get an indexOutOfBounds exception
new String[26]. This is causing theindexOutOfBoundsException