1
我寫了下面的代碼:Files.newDirectoryStream()拋出AccessDeniedException異常的根在Windows XP
void backupFileAttributes(Path path, BufferedWriter writer) throws IOException
{
try
{
if (Files.isReadable(path))
{
DirectoryStream<Path> stream = Files.newDirectoryStream(path);
for (Path entry : stream)
{
BasicFileAttributes attr = Files.readAttributes(entry, BasicFileAttributes.class);
if (Files.isDirectory(entry))
{
writer.append((getFileData(entry, attr)));
writer.newLine();
backupFileAttributes(entry, writer);
}
writer.append(getFileData(entry, attr));
writer.newLine();
}
}
else
{
System.out.println("Could not read directory: " + path.toAbsolutePath());
}
}
catch (java.nio.file.AccessDeniedException e)
{
System.out.println("Access was denied on path: " + path.toAbsolutePath());
}
}
然而,行
DirectoryStream<Path> stream = Files.newDirectoryStream(path);
上C:\
使用時拋出AccessDeniedException異常在Windows XP。我需要使用Path的Java 7實用程序。