Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
FileUtil.java
Go to the documentation of this file.
1 package org.bukkit.util;
2 
3 import java.nio.channels.FileChannel;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 
13 public class FileUtil {
14 
23  public static boolean copy(File inFile, File outFile) {
24  if (!inFile.exists()) {
25  return false;
26  }
27 
28  FileChannel in = null;
29  FileChannel out = null;
30 
31  try {
32  in = new FileInputStream(inFile).getChannel();
33  out = new FileOutputStream(outFile).getChannel();
34 
35  long pos = 0;
36  long size = in.size();
37 
38  while (pos < size) {
39  pos += in.transferTo(pos, 10 * 1024 * 1024, out);
40  }
41  } catch (IOException ioe) {
42  return false;
43  } finally {
44  try {
45  if (in != null) {
46  in.close();
47  }
48  if (out != null) {
49  out.close();
50  }
51  } catch (IOException ioe) {
52  return false;
53  }
54  }
55 
56  return true;
57 
58  }
59 }