0

I am trying to Zip file using ZipOutputStream but it's throwing StringIndexOutOfBoundsException while passing a FileOutPutStream object. The code was working fine when I ran it as a separate java class but when I integrated it with my project, it's throwing the exception.

I used this code:

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());
        }
Appulus
  • 18,630
  • 11
  • 38
  • 46

0 Answers0