ZipOutPutStream抛出StringIndexOutOfBoundsException

时间:2013-12-06 15:57:18

标签: java

我正在尝试使用ZipOutputStream压缩文件,但是在传递StringIndexOutOfBoundsException对象时它会抛出FileOutPutStream。 当我将它作为一个单独的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());
        }

0 个答案:

没有答案
相关问题