Mercurial Hosting > luan
comparison src/goodjava/io/IoUtils.java @ 1493:471ef3e6a84e
more io
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 May 2020 00:12:15 -0600 |
parents | af55cfad6e12 |
children | 91c167099462 |
comparison
equal
deleted
inserted
replaced
1492:aaac1d29edea | 1493:471ef3e6a84e |
---|---|
1 package goodjava.io; | 1 package goodjava.io; |
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.InputStream; | |
5 import java.io.OutputStream; | |
4 import java.io.IOException; | 6 import java.io.IOException; |
5 import java.nio.file.Files; | 7 import java.nio.file.Files; |
6 | 8 |
7 | 9 |
8 public final class IoUtils { | 10 public final class IoUtils { |
31 | 33 |
32 public static void link(File from,File to) throws IOException { | 34 public static void link(File from,File to) throws IOException { |
33 Files.createLink( to.toPath(), from.toPath() ); | 35 Files.createLink( to.toPath(), from.toPath() ); |
34 } | 36 } |
35 | 37 |
38 public static long copyAll(InputStream in,OutputStream out) | |
39 throws IOException | |
40 { | |
41 long total = 0; | |
42 byte[] a = new byte[8192]; | |
43 int n; | |
44 while( (n=in.read(a)) != -1 ) { | |
45 out.write(a,0,n); | |
46 total += n; | |
47 } | |
48 return total; | |
49 } | |
50 | |
36 } | 51 } |