1
我需要讀取文件中的數字列表並將其存儲到2d數組中。 這是我到目前爲止。我將如何去實現這個目標?讀取文件,將字符串轉換爲double,存儲在2d數組中
//this is only part of my code
public class RainFall
{
double[][] precip;
public RainFall()
{
precip = new double [5][12];
}
public void readFile(BufferedReader infile) throws IOException
{
FileInputStream infile = new FileInputStream("numbers.dat");
BufferedReader br = new BufferedReader(new InputStreamReader(infile));
String[][] myarray = new String[5][12];
while (infile.readLine() != null)
{
for (int j = 0; j < 5; j++)
{
for (int i = 0; i < 12; i++)
{
myarray[j][i] = infile.readLine();
}
}
}
infile.close();
}
numbers.dat是60行:
1.01
0.03
2.14
0.47
後如何數字在每一行分開的文件看起來像 – 2011-02-09 02:59:07
的樣本?你能提供一些樣本數據嗎?每行上的數字數量是否相同? – 2011-02-09 03:00:17