public static long getFolderSize(String path) throws IOException {
final AtomicLong size = new AtomicLong(0);
Path directoryPath = Paths.get(path);
try {
Files.walkFileTree(directoryPath, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) {
size.addAndGet(attrs.size());
return FileVisitResult.CONTINUE;
}
});
} catch (NoSuchFileException ignored) {
}
return size.get();
}
final AtomicLong size = new AtomicLong(0);
Path directoryPath = Paths.get(path);
try {
Files.walkFileTree(directoryPath, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) {
size.addAndGet(attrs.size());
return FileVisitResult.CONTINUE;
}
});
} catch (NoSuchFileException ignored) {
}
return size.get();
}
留言
張貼留言