Java ZipOutStream抛出StringIndexOutfBoundsException
我试图使用Java ZipOutStream抛出StringIndexOutfBoundsException,java,Java,我试图使用ZipOutputStream压缩文件,但它在传递FileOutPutStream对象时抛出stringindexoutofboundseception。 当我将代码作为一个单独的java类运行时,它运行得很好,但是当我将它与我的项目集成时,它抛出了异常 我使用了以下代码: byte[] buffer = new byte[1024]; try{ FileOutputStream fos = new FileOutputStream("C:\\Report.zip");
ZipOutputStream
压缩文件,但它在传递FileOutPutStream
对象时抛出stringindexoutofboundseception
。
当我将代码作为一个单独的java类运行时,它运行得很好,但是当我将它与我的项目集成时,它抛出了异常
我使用了以下代码:
byte[] buffer = new byte[1024];
try{
FileOutputStream fos = new FileOutputStream("C:\\Report.zip");
//error throwing at this point (java.lang.StringIndexOutOfBoundsException)
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos));
FileInputStream in = new FileInputStream("C:\\Report.xls");
zos.putNextEntry(new ZipEntry("Report.xls"));
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
zos.closeEntry();
zos.close();
}catch(IOException ex){
Log.report.debug(ex.toString());
}
请发布完整的stacktraceWhere是您的
缓冲区
?嗨,Ryan,stacktracebuffer数组中显示的唯一内容没有声明。@user2677254不,没有声明。堆栈跟踪应如下所示: