Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.util;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileOutputStream;
6import java.io.IOException;
7import java.nio.channels.FileChannel;
8
9/**
10 * Class containing file utilities
11 */
12
13public class FileUtil {
14
15 /**
16 * This method copies one file to another location
17 *
18 * @param inFile the source filename
19 * @param outFile the target filename
20 * @return true on success
21 */
22
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}