因此,关于Stackoverflow的此错误,有几篇文章,但是它们均未应用/修复特权。因此,我正在构建一个应用程序,使您可以从远程计算机访问文件,列出目录中/目录中的所有文件,然后通过网络发送其中一个文件。如果您需要从家用计算机上获取文件,但无法访问它。
所以,我很幸运地找到了一些可以轻松列出从x目录开始的所有文件的东西,就是这样:
Files.walk(Paths.get(startPath)).filter(Files::isRegularFile).forEach(System.out::println);
这适用于我系统上的许多目录,但是对于某些目录(通常在运行时中间弹出),它会给我以下错误:
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
当我看到“访问被拒绝”时,我以为管理员特权可以解决此问题,因此我以特权重新启动了Eclipse,我认为该特权适用于某些文件,但是仍然出现此错误。关于如何解决它的任何想法?