1473
|
1 package goodjava.io;
|
|
2
|
|
3 import java.io.File;
|
|
4 import java.io.IOException;
|
|
5 import java.nio.file.Files;
|
|
6
|
|
7
|
|
8 public final class IoUtils {
|
|
9 private IoUtils() {} // never
|
|
10
|
|
11 public static void move( File from, File to ) throws IOException {
|
|
12 Files.move( from.toPath(), to.toPath() );
|
|
13 }
|
|
14
|
|
15 public static void delete(File file) throws IOException {
|
|
16 Files.deleteIfExists( file.toPath() );
|
|
17 }
|
1475
|
18
|
|
19 public static boolean isSymbolicLink(File file) {
|
|
20 return Files.isSymbolicLink(file.toPath());
|
|
21 }
|
|
22
|
|
23 public static void deleteRecursively(File file) throws IOException {
|
|
24 if( file.isDirectory() && !isSymbolicLink(file) ) {
|
|
25 for( File f : file.listFiles() ) {
|
|
26 deleteRecursively(f);
|
|
27 }
|
|
28 }
|
|
29 delete(file);
|
|
30 }
|
|
31
|
1488
|
32 public static void link(File from,File to) throws IOException {
|
|
33 Files.createLink( to.toPath(), from.toPath() );
|
|
34 }
|
|
35
|
1473
|
36 } |