deleting file java.util.zip

Hi!

I am developing Java application using ZipFile API. Platform is Windows XP. I am facing following problem.

Basically, this application pools the Zip files from one source folder and unzip it into another folder. Everything is working fine,

But the only problem is while deleting original zip file from its source location. I am not able to delete it. I tried each and every possible ways even silly things. I am not able to Delete it from Windows Explorer.

But at the same time I have noticed that if I tried to overwrite same file (from other location) using Windows explorer it does.

Anyone can help me out. The source folder is watch folder so i need to delete that file. Following is the code.

1) To Unzip the file

<code>

public boolean unZipFiles(String fromZip, String toLocation) {

String seperator = System.getProperty("file.separator");

logger.info("unzipping zip file "+fromZip+" to "+toLocation);

System.out.println("unzipping zip file to "+toLocation);

try {

File zipDir = new File(toLocation);

zipDir.mkdir();

ZipFile zip = new ZipFile(fromZip);

for (Enumeration entries = zip.entries(); entries.hasMoreElements();) {

ZipEntry e = ((ZipEntry) entries.nextElement());

FileOutputStream fos = new FileOutputStream(toLocation + seperator + e.getName());

BufferedOutputStream ost = new BufferedOutputStream(fos,512);

createFile(zip.getInputStream(e), ost);

ost.close();

fos.close();

}

zip.close();//Added by PD

} catch (Exception ex) {

logger.error("Error unzipping zip file "+fromZip +" to "+toLocation, ex);

return false;

}

logger.info("unzipped zip file "+fromZip+" to "+toLocation);

System.out.println("unzipped zip file to "+toLocation);

return true;

}

</code>

2) To Delete the files

private static void cleanupFolder(String inFolder) {

try {

File inFolderFile = new File(inFolder);

File[] filelist = inFolderFile.listFiles();

for (int i = 0; i < filelist.length; i++) {

File fileWithPath = new File(filelist.toString());

FileUtils.forceDelete(fileWithPath);

}

} catch (Exception ex) {

logger.error(ex);

// ex.printStackTrace();

}

}

Message was edited by:

PiyushDesai

[2403 byte] By [PiyushDesaia] at [2007-11-27 10:26:41]
# 1

> File fileWithPath = new File(filelist.toString());

File fileWithPath = filelist[i];

> FileUtils.forceDelete(fileWithPath);

As you haven't shown us what this does it's not possible to tell you what's wrong with it.

ejpa at 2007-7-28 17:40:54 > top of Java-index,Core,Core APIs...
# 2

This shows the location from where files to be deleted.

Unzip is being done from this location only.

PiyushDesaia at 2007-7-28 17:40:54 > top of Java-index,Core,Core APIs...
# 3

> This shows the location from where files to be deleted.

Rubbish. It doesn't do any such thing.

> FileUtils.forceDelete(fileWithPath);

As you still haven't shown us what this does, it's still not possible to tell you what's wrong with it.

ejpa at 2007-7-28 17:40:54 > top of Java-index,Core,Core APIs...