我有以下問題:顯示java.lang.NullPointerException:吹氣已關閉在InputStreamReader的
當我從該項目的所有工作正常加載資源,但是當我把它放在一個.jar和嘗試加載我得到一個異常。
的代碼是:
InputStreamReader reader =
new InputStreamReader(
this.getClass().getResource(fileName).openStream())
CsvReader stream = new CsvReader(reader);
try {
while (stream.readRecord()) {
line = stream.getRawRecord();
//DO SOMETHING...
}
}catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
stream.close();
}
而且堆棧跟蹤是:
Inflater has been closed java.lang.NullPointerException: Inflater has been closed
at java.util.zip.Inflater.ensureOpen(Inflater.java:364)
at java.util.zip.Inflater.inflate(Inflater.java:237)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:135)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at utils.csvreader.CsvReader.checkDataLength(CsvReader.java:1198)
at utils.csvreader.CsvReader.readRecord(CsvReader.java:604)
的問題發生在stream.getRawRecord()
。我也試過用BufferedReader在readLine();
有什麼想法?
您沒有關閉閱讀器。 – EJP 2016-12-30 23:08:21