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?