tools4j / unix4j

An implementation of Unix command line tools in Java.
unix4j.org
MIT License
236 stars 43 forks source link

The process cannot access the file because it is being used by another process #53

Closed nipunalk closed 3 years ago

nipunalk commented 6 years ago

Hi,

When I try to delete file after Unix4j.grep .it complains, file is used by another process. private void getTotalFilesFromControlFile(File file) {

    try {
    File dest=new File(file.getParentFile()+"\\copy"+file.getName());
    Files.copy(Paths.get(file.getAbsolutePath()),Paths.get( dest.getAbsolutePath()),StandardCopyOption.REPLACE_EXISTING);
    if (dest.exists() ) {

        String lines = Unix4j.grep(TOTAL_FILES, dest).toLineList();

    Files.delete(Paths.get(dest.getAbsolutePath()));
    } 

    }
    catch(Exception e) {
    System.out.println(e.getMessage()); 
    }

}
terzerm commented 6 years ago

Thanks for reporting this bug. I will look into it and provide a fix asap.

DEV Remark: Can only be reproduced on Windows.

terzerm commented 6 years ago

This has been fixed on master and will be released in Version 0.6 some time soon.

stormboomer commented 3 years ago

I am facing the same issue at the moment. It seems that 0.5 is still the latest version available via the maven Repository. Is there a plan on releasing Version 0.6 and pushing it to the maven Repository?

terzerm commented 3 years ago

I will look into releasing 0.6.