1 package org
.argeo
.util
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.FileVisitResult
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
7 import java
.nio
.file
.SimpleFileVisitor
;
8 import java
.nio
.file
.attribute
.BasicFileAttributes
;
10 /** Utilities around the standard Java file abstractions. */
11 public class FsUtils
{
13 * Deletes this path, recursively if needed. Does nothing if the path does not
16 public static void delete(Path path
) {
18 if (!Files
.exists(path
))
20 Files
.walkFileTree(path
, new SimpleFileVisitor
<Path
>() {
22 public FileVisitResult
postVisitDirectory(Path directory
, IOException e
) throws IOException
{
25 Files
.delete(directory
);
26 return FileVisitResult
.CONTINUE
;
30 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
32 return FileVisitResult
.CONTINUE
;
35 } catch (IOException e
) {
36 throw new RuntimeException("Cannot delete " + path
, e
);