public static void main(String argv[]){
try
{
String date=new java.text.SimpleDateFormat("MM-dd-yyyy").format(new java.util.Date());
File inFolder=new File("Output/" + date + "_4D");
File outFolder=new File("Output/" + date + "_4D" + ".zip");
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inFolder.list();
for (int i=0; i<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream(inFolder.getPath() + "/" + files[i]), 1000);
out.putNextEntry(new ZipEntry(files[i]));
int count;
while((count = in.read(data,0,1000)) != -1)
{
out.write(data, 0, count);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Am trying to zip a folder which contains subfolders. Trying to zip the folder named 10-18-2010_4D.The above programs ends with the following exception. Please advise on how to clear the issue.
java.io.FileNotFoundException: Output\10-18-2010_4D\4D (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at ZipFile.main(ZipFile.java:17)