我正在使用Apache Ant中的BZip2压缩库。文档链接如下:
http://javadoc.haefelinger.it/org.apache.ant/1.7.1/org/apache/tools/bzip2/CBZip2InputStream.html
但是在运行代码时,我一直收到以下错误提示:
错误出现在第 - 行。
非常感谢您的帮助。
Exception in thread "main" java.lang.NullPointerException
at org.apache.tools.bzip2.CBZip2InputStream.bsR(CBZip2InputStream.java:323)
at org.apache.tools.bzip2.CBZip2InputStream.bsGetUChar(CBZip2InputStream.java:341)
at org.apache.tools.bzip2.CBZip2InputStream.initBlock(CBZip2InputStream.java:230)
at org.apache.tools.bzip2.CBZip2InputStream.<init>(CBZip2InputStream.java:178)
at org.apache.tools.bzip2.bzipCompression.main(bzipCompression.java:37)
错误出现在第 - 行。
**CBZip2InputStream cin = new CBZip2InputStream(fileInputStream);**
我的源代码是 -
public static void main(String[] args) throws IOException, NullPointerException {
// TODO Auto-generated method stub
FileReader inFile = new FileReader("alice29.txt");
BufferedReader buff = new BufferedReader(inFile);
FileOutputStream fout = new FileOutputStream("alicea.txt");
fout.write("BZ".getBytes());
CBZip2OutputStream czout = new CBZip2OutputStream (fout);
String message = buff.readLine(); // read first line
while(message!=null){
byte[] input = message.getBytes();
czout.write(input);
message = buff.readLine();
}
czout.flush();
czout.close();
InputStream fileInputStream = new FileInputStream("alicea.txt");
CBZip2InputStream cin = new CBZip2InputStream(fileInputStream);
FileOutputStream decOut = new FileOutputStream("decompressedAlice.txt");
byte[] buf = new byte[100000];
int len;
while((len = cin.read(buf))>0){
decOut.write(buf, 0, len);
}
decOut.close();
cin.close();
}
非常感谢您的帮助。