-1
我正在嘗試使用FileReader
來讀文件,但我正在獲取空指針訪問權限。以下是代碼。你能告訴我錯誤是什麼。在使用FileReader時出現空指針訪問錯誤
public class C {
private static final String file = "a.csv";
public static void main(String[] args) {
try (BufferedReader br2 = new BufferedReader(new FileReader(file))) {
String line1;
while ((line1 = br2.readLine()) != null);
{
System.out.println(line1);
String[] rules = line1.split(",");
String sevkey = rules[0];
String sevval = rules[1];
String[] val = sevval.split("\\|");
String actsevval = val[1];
HashMap<String, String> sevs = new HashMap<String, String>();
for (int i = 0; i <= sevs.size(); i++) {
sevs.put(sevkey, actsevval);
if (actsevval != "none") {
System.out.println(actsevval);
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
請包括堆棧跟蹤告訴你的堆棧跟蹤 – AMB
。請閱讀。 – duffymo
'while((line1 = br2.readLine())!= null);'刪除這裏的分號 – DimaSan