Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
FileUtil.java
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 
9 /**
10  * Class containing file utilities
11  */
12 public class FileUtil {
13 
14  /**
15  * This method copies one file to another location
16  *
17  * @param inFile the source filename
18  * @param outFile the target filename
19  * @return true on success
20  */
21  public static boolean copy(File inFile, File outFile) {
22  if (!inFile.exists()) {
23  return false;
24  }
25 
26  FileChannel in = null;
27  FileChannel out = null;
28 
29  try {
30  in = new FileInputStream(inFile).getChannel();
31  out = new FileOutputStream(outFile).getChannel();
32 
33  long pos = 0;
34  long size = in.size();
35 
36  while (pos < size) {
37  pos += in.transferTo(pos, 10 * 1024 * 1024, out);
38  }
39  } catch (IOException ioe) {
40  return false;
41  } finally {
42  try {
43  if (in != null) {
44  in.close();
45  }
46  if (out != null) {
47  out.close();
48  }
49  } catch (IOException ioe) {
50  return false;
51  }
52  }
53 
54  return true;
55 
56  }
57 }
static boolean copy(File inFile, File outFile)
Definition: FileUtil.java:21