當我嘗試運行這個基準java8-lambda-benchmark。在java程序中加載一個csv文件
使用COMAND:
java -cp build/jar/LambdaMicrobench.jar lambdademo.LambdaAvgExtraParallel 50000
我得到以下錯誤:
lambdademo/load_employees.csv: Not found in jar
java.lang.NullPointerException
at lambdademo.EmployeeFile.loadEmployeeList(Unknown Source)
at lambdademo.LambdaAvgExtraParallel.main(Unknown Source)
Exception in thread "main" java.lang.NullPointerException
at lambdademo.EmployeeFile.loadEmployeeList(Unknown Source)
at lambdademo.LambdaAvgExtraParallel.main(Unknown Source
文件EmployeFile.java如下:
public class EmployeeFile {
private static final String EMPLOYEE_FILE = "lambdademo/load_employees.csv";
public LinkedList<EmployeeRec> loadEmployeeList() {
LinkedList<EmployeeRec> employeeList = new LinkedList<>();
BufferedReader br = null;
try {
URL fileURL = getClass().getClassLoader().getResource(EMPLOYEE_FILE);
if (fileURL == null) {
System.out.println("resource is null");
}
InputStream in = fileURL.openStream();
br = new BufferedReader(new InputStreamReader(in));
} catch (Exception e) {
System.out.println(EMPLOYEE_FILE + ": Not found in jar");
e.printStackTrace();
}
try {
String line;
while ((line = br.readLine()) != null) {
String[] rec = null;
rec = line.split(",");
employeeList.add(new EmployeeRec(rec[0], rec[1], rec[2],
rec[3], rec[4], rec[5]));
}
} catch (IOException e) {
System.out.println("Error reading " + EMPLOYEE_FILE);
e.printStackTrace();
}
return employeeList;
}
現在我打印的價值fileURL我得到空。 csv
文件與項目的來源位於同一文件夾內。
喲喲你創建'LambdaMicrobench.jar'(例如使用IDE,Maven,螞蟻......)?你可以確認'.csv'是否在正確的位置,在'.jar'(一個'.jar'是'.zip'文件,只需使用7zip/unzip/tar或類似的工具來解壓它的內容) ? – Pyranja
我用ant編譯:'ant -buildfile build.xml' – Bionix1441