/** * Converts file URLs to file. Ignores other schemes and returns <code>null</code>. */ public static File toFile(URL url) { String fileName = toFileName(url); if (fileName == null) { return null; } return file(fileName); }
public static File moveFileToDir(File src, File destDir, FileUtilParams params) throws IOException { if (destDir.exists() && !destDir.isDirectory()) { throw new IOException(MSG_NOT_A_DIRECTORY + destDir); } return moveFile(src, file(destDir, src.getName()), params); }
/** * Creates single folder. * @see #mkdir(java.io.File) */ public static void mkdir(String dir) throws IOException { mkdir(file(dir)); } /**
/** * @see #touch(java.io.File) */ public static void touch(String file) throws IOException { touch(file(file)); } /**
/** * Creates all folders at once. * @see #mkdirs(java.io.File) */ public static void mkdirs(String dirs) throws IOException { mkdirs(file(dirs)); } /**
/** * Copies a file to folder with specified copy params and returns copied destination. */ public static File copyFileToDir(File src, File destDir, FileUtilParams params) throws IOException { if (destDir.exists() && !destDir.isDirectory()) { throw new IOException(MSG_NOT_A_DIRECTORY + destDir); } File dest = file(destDir, src.getName()); copyFile(src, dest, params); return dest; }
public static void deleteDir(String dest) throws IOException { deleteDir(file(dest), fileUtilParams); } public static void deleteDir(String dest, FileUtilParams params) throws IOException {
public static void cleanDir(String dest) throws IOException { cleanDir(file(dest), fileUtilParams); } public static void cleanDir(String dest, FileUtilParams params) throws IOException {
public static void cleanDir(String dest, FileUtilParams params) throws IOException { cleanDir(file(dest), params); } public static void cleanDir(File dest) throws IOException {
public static String[] readLines(String source) throws IOException { return readLines(file(source), fileUtilParams.encoding); } public static String[] readLines(String source, String encoding) throws IOException {
public static void writeChars(String dest, char[] data, String encoding) throws IOException { outChars(file(dest), data, encoding, false); }
public static void appendString(String dest, String data, String encoding) throws IOException { outString(file(dest), data, encoding, true); }
private static void doMoveDirectory(File src, File dest) throws IOException { if (dest.exists()) { if (!dest.isDirectory()) { throw new IOException(MSG_NOT_A_DIRECTORY + dest); } dest = file(dest, dest.getName()); dest.mkdir(); } final boolean rename = src.renameTo(dest); if (!rename) { doCopyDirectory(src, dest, params()); deleteDir(src); } }