1473
|
1 package goodjava.io;
|
|
2
|
|
3 import java.io.File;
|
1493
|
4 import java.io.InputStream;
|
|
5 import java.io.OutputStream;
|
1473
|
6 import java.io.IOException;
|
|
7 import java.nio.file.Files;
|
|
8
|
|
9
|
|
10 public final class IoUtils {
|
|
11 private IoUtils() {} // never
|
|
12
|
|
13 public static void move( File from, File to ) throws IOException {
|
|
14 Files.move( from.toPath(), to.toPath() );
|
|
15 }
|
|
16
|
|
17 public static void delete(File file) throws IOException {
|
|
18 Files.deleteIfExists( file.toPath() );
|
|
19 }
|
1475
|
20
|
|
21 public static boolean isSymbolicLink(File file) {
|
|
22 return Files.isSymbolicLink(file.toPath());
|
|
23 }
|
|
24
|
|
25 public static void deleteRecursively(File file) throws IOException {
|
|
26 if( file.isDirectory() && !isSymbolicLink(file) ) {
|
|
27 for( File f : file.listFiles() ) {
|
|
28 deleteRecursively(f);
|
|
29 }
|
|
30 }
|
|
31 delete(file);
|
|
32 }
|
|
33
|
1497
|
34 public static void link(File existing,File link) throws IOException {
|
|
35 Files.createLink( link.toPath(), existing.toPath() );
|
|
36 }
|
|
37
|
|
38 public static void symlink(File existing,File link) throws IOException {
|
|
39 Files.createSymbolicLink( link.toPath(), existing.toPath() );
|
1488
|
40 }
|
|
41
|
1494
|
42 public static void copyAll(InputStream in,OutputStream out)
|
1493
|
43 throws IOException
|
|
44 {
|
|
45 byte[] a = new byte[8192];
|
|
46 int n;
|
|
47 while( (n=in.read(a)) != -1 ) {
|
|
48 out.write(a,0,n);
|
|
49 }
|
|
50 }
|
|
51
|
1473
|
52 } |