通过读取Java

时间:2017-10-22 20:51:02

标签: java arrays loops file-io

问题和错误: 好吧,我有一个文件,有12个值,我正在读到程序,我正在尝试将它们分配给一个数组。我收到的错误如下:

java.lang.ArrayIndexOutOfBoundsException: 0
at HeatIndex.main(HeatIndex.java:14)

CODE: 以下代码包含Main方法中的所有内容:

public static void main(String args[]) throws IOException{
    //creating objects
    Scanner inFileTemp = new Scanner(new File("temp.txt"));
    Scanner inFileHum = new Scanner(new File("humidity.txt"));

    //creating variables and arrays
    double tempArray[] = {};
    double humArray[] = {};

    for(int i = 0; i < 12; i++){
        tempArray[i] = inFileTemp.nextDouble();
        humArray[i] = inFileHum.nextDouble();
    }
}

我试过的一些事情: 如果有人能够帮助或引导我朝着正确的方向前进,那就太棒了!我意识到这可能是一个简单的问题,但这里有一些我尝试改变的事情:

So the file has 12 values I tried changing the terminator to 13 and 11 but I 
still received the same error.

我也尝试过:

Changing the counting variable from 0 to 1 and so on.

非常感谢任何解释或帮助。

0 个答案:

没有答案