Chiddix

Untitled

Sep 16th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. /*I'm trying to make a program that prints all the files on your computer using Files.walkFileTree. It kinda works but before it can finish it trys to access c:\Documents and Settings and throws a AccessDeniedException. How can I prevent this?*/
  2.  
  3.     public static void main(String[] args) {
  4.         try {
  5.             final long start = System.nanoTime();
  6.  
  7.             Files.walkFileTree(Paths.get("c:/"), new SimpleFileVisitor<Path>() {
  8.                 @Override
  9.                 public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException {
  10.                     System.out.println(path.toFile().getName());
  11.                     return FileVisitResult.CONTINUE;
  12.                 }
  13.             });
  14.  
  15.             System.out.println("Finished in: " + (System.nanoTime() - start));
  16.         } catch (IOException e) {
  17.             e.printStackTrace();
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment