001    package org.bukkit.util;
002    
003    import java.nio.channels.FileChannel;
004    import java.io.File;
005    import java.io.FileInputStream;
006    import java.io.FileOutputStream;
007    import java.io.IOException;
008    
009    /**
010     * Class containing file utilities
011     */
012    public class FileUtil {
013    
014        /**
015         * This method copies one file to another location
016         *
017         * @param inFile the source filename
018         * @param outFile the target filename
019         * @return true on success
020         */
021        public static boolean copy(File inFile, File outFile) {
022            if (!inFile.exists()) {
023                return false;
024            }
025    
026            FileChannel in = null;
027            FileChannel out = null;
028    
029            try {
030                in = new FileInputStream(inFile).getChannel();
031                out = new FileOutputStream(outFile).getChannel();
032    
033                long pos = 0;
034                long size = in.size();
035    
036                while (pos < size) {
037                    pos += in.transferTo(pos, 10 * 1024 * 1024, out);
038                }
039            } catch (IOException ioe) {
040                return false;
041            } finally {
042                try {
043                    if (in != null) {
044                        in.close();
045                    }
046                    if (out != null) {
047                        out.close();
048                    }
049                } catch (IOException ioe) {
050                    return false;
051                }
052            }
053    
054            return true;
055    
056        }
057    }