java copy file

http://www.oschina.net/question/565065_58510

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  
private static void nioTransferCopy(File source, File target) {
  
FileChannel in = null;
  
FileChannel out = null;
  
FileInputStream inStream = null;
  
FileOutputStream outStream = null;
  
try {
  
inStream = new FileInputStream(source);
  
outStream = new FileOutputStream(target);
  
in = inStream.getChannel();
  
out = outStream.getChannel();
  
in.transferTo(0, in.size(), out);
  
} catch (IOException e) {
  
e.printStackTrace();
  
} finally {
  
close(inStream);
  
close(in);
  
close(outStream);
  
close(out);
  
}
  
}