-1
我正在嘗試讀取具有大約2000列和7行的csv文件的內容。我得到以下錯誤。在閱讀java中的csv文件時在256行處截斷預覽
Exception in thread "main" java.lang.NumberFormatException: For input string: "Preview truncated at 256 rows"
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 java.lang.Double.valueOf(Double.java:502)
請在下面找到
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.math3.analysis.function.Log;
public class GoogleFailureGenerator{
private ArrayList<Long>hostID = new ArrayList<Long>();
private ArrayList<Double>MTBF = new ArrayList<Double>();
private ArrayList<Double>MTTR = new ArrayList<Double>();
private ArrayList<Double>SD_TBF = new ArrayList<Double>();
private ArrayList<Double>Var_TBF = new ArrayList<Double>();
private ArrayList<Double>SD_TTR = new ArrayList<Double>();
private ArrayList<Double>Var_TTR = new ArrayList<Double>();
public void failInfo(){
BufferedReader buffer;
try {
buffer = new BufferedReader(new FileReader("C://Data/Australia/Information_for_Cloudsim.csv"));
buffer.readLine(); //Skips the first line of the file.
String currentstr;
while((currentstr=buffer.readLine()) != null){
String[] column = currentstr.split(",");
//System.out.println("column[0] = " +column[0]);
if(column.length>0){
//hostID.add(Long.parseLong(column[0]));
hostID.add(Double.valueOf(column[0]).longValue());
MTBF.add(Double.parseDouble(column[1]));
SD_TBF.add(Double.parseDouble(column[2]));
Var_TBF.add(Double.parseDouble(column[3]));
MTTR.add(Double.parseDouble(column[4]));
SD_TTR.add(Double.parseDouble(column[5]));
Var_TTR.add(Double.parseDouble(column[6]));
}
}
}
catch (IOException e) {
e.printStackTrace();
System.out.println("The simulation has been terminated due to an IO error");
}
}
public static void main(String args[]){
GoogleFailureGenerator failgen = new GoogleFailureGenerator();
failgen.failInfo();
}
}
任何幫助的代碼將是非常可觀的。
在此先感謝。
約傑什夏爾馬
可能重複[如何解決java.lang.NumberFormatException:對於輸入字符串:「N/A」?](http://stackoverflow.com/questions/18711896/how-to-resolve-java-lang- numberformatexception-for-input-string-na) – 4castle
你正試圖解析'預覽截斷在256行'的字符串值爲'double'值... – MadProgrammer