我有這樣的代碼來讀取文本文件中的數據並將其分配給二維數組閱讀文本文件
Scanner read_blockage = null;
General_Inputs.Blockage_Number=new double[Input.General_Inputs.Num_Of_Analysis_Years*Input.General_Inputs.Num_Of_States][Input.General_Inputs.Num_Of_Ppes];
try{
read_blockage=new Scanner(new File("Blockage Output1"));
int row = -1; // since we're incrementing row at the start of the loop
while(read_blockage.hasNext()) {
row++;
String[] line = read_blockage.nextLine().split("\t");
for(int j=0;j<Input.General_Inputs.Num_Of_Ppes;j++){
try {
General_Inputs.Blockage_Number[row][j] = Double.parseDouble(line[j]);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}}
read_blockage.close();}catch (FileNotFoundException e) {
e.printStackTrace();
}
但我得到這個錯誤:
java.io.FileNotFoundException: Blockage Output1 (The system cannot find the file specified)
2
2
2
3
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.util.Scanner.<init>(Scanner.java:611)
at Input.Get_Inputs(Input.java:270)
at Input.main(Input.java:288)
我我不確定爲什麼這個錯誤會發生任何建議?
編輯: 我擺脫上述錯誤的,但現在我有一個新的錯誤:
java.lang.NumberFormatException: For input string: "0.2810496821150867 0.3455471819235053 0.1247760656600859 0.1925735036025203 0.16475561749067555 0.3267969645821732 0.5325079154577266 0.7311354592633524 0.29828747755582985 0.3983939064000447 1.6432540332118697 2.242416989842468 0.8199042126197025 1.1448149650482649 0.6569387483611318 0.35521248909704994 0.8311372587904973 1.2599707232227086 1.4153816162469934 1.091443886313361 0.7492391207620115 1.4029328027711394 1.3060173850919903 3.0212129386585675 1.185220575726193 3.2093022651230037 2.2304670167490195 4.028061408800144 1.1957020911741867 2.3250822033050813 6.144104904071859 9.634733755857885 3.3148373093880736 9.740483573762857 3.857137427951027 4.527035922001198 7.248709304936811 10.112180962036412 12.688211002013142 3.5445943135631026 5.87022858087266 11.490999298946353 13.75534054772614"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at Input.Get_Inputs(Input.java:277)
at Input.main(Input.java:288)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Input.Get_Inputs(Input.java:277)
at Input.main(Input.java:288)
任何建議?
文件「Blockage Output1」是否存在?它位於進程的工作目錄中嗎? – hexafraction
@hexafraction是的我只是編輯它在方法開始時存在的帖子。此代碼是更大代碼的一部分 –
不,我的意思是稱爲「Blockage Output1」的文本文件本身。它存在於磁盤上嗎?你確定它不叫做「Blockage Output1.txt」嗎? – hexafraction