1

So, there are a few posts about this error on Stackoverflow, but neither of them applied/fixed the privileges. So, I am building an application that will let you access files from a remote computer, list all the files on it/in a directory, and then send one of those over a network. In the event of where you need a file from your home computer, but can't access it.

So, I was fortunate enough to find something that would easily list all the files starting from x directory, and that's this:

Files.walk(Paths.get(startPath)).filter(Files::isRegularFile).forEach(System.out::println);

This works for a lot of the directories on my system, but for some, (which usually pop up during the middle of the runtime) it gives me the following error:

Exception in thread "main" java.io.UncheckedIOException: java.nio.file.AccessDeniedException: C:\Users\Name\AppData\Local\Application Data
    at java.nio.file.FileTreeIterator.fetchNextIfNeeded(Unknown Source)
    at java.nio.file.FileTreeIterator.hasNext(Unknown Source)
    at java.util.Iterator.forEachRemaining(Unknown Source)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.forEach(Unknown Source)
    at RecursiveFileFinder.main(RecursiveFileFinder.java:7)
Caused by: java.nio.file.AccessDeniedException: C:\Users\Name\AppData\Local\Application Data
    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.WindowsDirectoryStream.<init>(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(Unknown Source)
    at java.nio.file.Files.newDirectoryStream(Unknown Source)
    at java.nio.file.FileTreeWalker.visit(Unknown Source)
    at java.nio.file.FileTreeWalker.next(Unknown Source)
    ... 11 more

As soon as I saw "Access Denied", I assumed administrator privileges would fix this, so I restarted Eclipse with the privileges, which I believe worked for some files, but I'm still getting this error. Any idea on how to fix it?

  • You're right: starting Eclipse with admin privileges allows you to run java with the same rights. Probably not even administrator can access `C:\Users\Name\AppData\Local\Application Data`. – Robert Hume Jun 29 '18 at 22:03
  • 1
    *"neither of them applied/fixed the privileges"* The only "fix" is to **skip** sub-folders you're not authorized to use. There is a *reason* you're not authorized to see the content of some folders, not even as an administrator: They're private files belonging to another user. – Andreas Jun 29 '18 at 22:04
  • 1
    If you're asking the *Windows-specific* question of how to grant yourself access to files that you otherwise don't have access to, that is a question you should ask on https://superuser.com/ or maybe https://serverfault.com/ – Andreas Jun 29 '18 at 22:10

0 Answers0