This discussion is archived
2 Replies Latest reply: Oct 9, 2012 6:00 AM by linkin RSS

Files.copy java.nio.file.AccessDeniedException

967118 Newbie
Currently Being Moderated
Hello everybody,
I hope you are well, Me not.

I use this method to unzip

public void deziper(final Path zipFile, final Path destDir) throws IOException*
     {     
          // On crée un FileSystem associé à l'archive :
     try ( FileSystem zfs = FileSystems.newFileSystem(zipFile, null) ) {
     // On parcourt tous les éléments root :
     for (Path root : zfs.getRootDirectories()) {
     // Et on parcourt toutes leurs arborescences :
     Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
     private Path unzippedPath(Path path) {
return Paths.get(destDir.toString(), path.toString()).normalize();
     }

     @Override
     public FileVisitResult preVisitDirectory(Path dir,
     BasicFileAttributes attrs) throws IOException {
     // On crée chaque répertoire intermédiaire :
     Files.createDirectories(unzippedPath(dir));
     return FileVisitResult.CONTINUE;
     }

     @Override
     public FileVisitResult visitFile(Path file,
     BasicFileAttributes attrs) throws IOException {
     // Et on copie chaque fichier :
     Files.copy(file, unzippedPath(file), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
     return FileVisitResult.CONTINUE;
     }
     });
     }
     }
     }

Replace all files work well, but when application try to replace Executable Jar File in same directory This error is thrown

09oct.2012 13:52:12,484 - 0 [AWT-EventQueue-0] WARN barakahfx.ModuleUpdater - Exception
java.nio.file.AccessDeniedException: G:\Program Files\Djindo\Imanis\Djindo.jar
     at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
     at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
     at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
     at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
     at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
     at java.nio.file.Files.deleteIfExists(Unknown Source)
     at java.nio.file.CopyMoveHelper.copyToForeignTarget(Unknown Source)
     at java.nio.file.Files.copy(Unknown Source)
     at lib.GererFichier$3.visitFile(GererFichier.java:167)
     at lib.GererFichier$3.visitFile(GererFichier.java:150)
     at java.nio.file.FileTreeWalker.walk(Unknown Source)
     at java.nio.file.FileTreeWalker.walk(Unknown Source)
     at java.nio.file.FileTreeWalker.walk(Unknown Source)
     at java.nio.file.Files.walkFileTree(Unknown Source)
     at java.nio.file.Files.walkFileTree(Unknown Source)
     at lib.GererFichier.deziper(GererFichier.java:150)
     at barakahfx.ModuleUpdater.demarrerUpdate(ModuleUpdater.java:98)
     at barakahfx.AppliCtrl.demarrer(AppliCtrl.java:92)
     at barakahfx.BarakahFx$1.actionPerformed(BarakahFx.java:56)
     at javax.swing.Timer.fireActionPerformed(Unknown Source)
     at javax.swing.Timer$DoPostEvent.run(Unknown Source)
     at java.awt.event.InvocationEvent.dispatch(Unknown Source)
     at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
     at java.awt.EventQueue.access$200(Unknown Source)
     at java.awt.EventQueue$3.run(Unknown Source)
     at java.awt.EventQueue$3.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)

Thank you very match
Edited by: 964115 on Oct 9, 2012 5:39 AM

Edited by: 964115 on Oct 9, 2012 5:40 AM

Edited by: 964115 on Oct 9, 2012 5:46 AM

Edited by: 964115 on Oct 9, 2012 5:55 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points