jarchivelib
jarchivelib copied to clipboard
Deleteing file fails after Compressor.decompress()
Simple and clean API but I have an issue.
I am using a test file named fileNane.gz. It is not a compressed file but a text file with the .gz extension. This file seems to be locked by a process when trying to delete.
compressor.decompress(f, new File(f.getParent()) ) throws an exception as expected but I cannot delete the file.
Here is my code:
private boolean decompress(File f) {
try{
Compressor compressor = CompressorFactory.createCompressor(f);
System.out.println("COMPRESSED FILE");
compressor.decompress(f, new File(f.getParent()) );
FileUtils.deleteQuietly(f);
return true;
}catch(IllegalArgumentException e){
}catch(FileNotFoundException e){
}catch (Exception e) {
System.out.println(f.canExecute()); // is true
System.out.println(f.canRead()); // is true
System.out.println(f.canWrite()); // is true
System.out.println(f.exists()); // is true
System.out.println(f.delete()); // is false
System.err.println(e);
}
return false;
}
i can not replicate this on my system. i wrote a junit test:
@Test
public void test() throws Exception {
File source = new File("/tmp/fake.gz");
assertTrue(source.createNewFile());
Compressor compressor = CompressorFactory.createCompressor(source);
try {
compressor.decompress(source, new File(source.getParent()));
} catch (Exception e) {
assertTrue(source.exists());
assertTrue(source.delete());
assertFalse(new File("/tmp/fake.gz").exists());
}
}
and it runs through properly.
can you specify what environment you working are in?
- operating system
- java version
- in what type of environment are you executing the code?
Thank you for your quick response. I've done more testing and still receive the same error. Maybe it is a problem with the Java version?
Operating System: Windows 7 Java Version: 1.6.0_29 Environment: From Eclipse Luna as a java application. Also tested from Windows command prompt after creating an executable jar.
I've simplified the execution to this:
public static void main(String[] args){
File f = new File("document.txt.gz");
System.out.println("Java Version: "+ System.getProperty("java.version"));
try{
Compressor compressor = CompressorFactory.createCompressor(f);
compressor.decompress(f, new File(f.getParent()) );
}catch(IllegalArgumentException e){
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally{
System.out.println(f.delete());
}
}