Files
Paper/paper-api/src/main/java/org/bukkit/util/FileUtil.java
Bukkit/Spigot 855f4133b6 Whitespace + general cleanup
By: Erik Broes <erikbroes@grum.nl>
2011-05-14 23:22:54 +02:00

60 lines
1.3 KiB
Java

package org.bukkit.util;
import java.nio.channels.FileChannel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Class containing file utilities
*/
public class FileUtil {
/**
* This method copies one file to another location
*
* @param inFile the source filename
* @param outFile the target filename
* @return true on success
*/
public static boolean copy(File inFile, File outFile) {
if (!inFile.exists()) {
return false;
}
FileChannel in = null;
FileChannel out = null;
try {
in = new FileInputStream(inFile).getChannel();
out = new FileOutputStream(outFile).getChannel();
long pos = 0;
long size = in.size();
while (pos < size) {
pos += in.transferTo(pos, 10 * 1024 * 1024, out);
}
} catch (IOException ioe) {
return false;
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
return false;
}
}
return true;
}
}