/** * 创建新文件,如果父目录不存在,也一并创建。可接受 null 参数 * * @param f * 文件对象 * @return false,如果文件已存在。 true 创建成功 * @throws IOException */ public static boolean createNewFile(File f) throws IOException { if (null == f || f.exists()) return false; makeDir(f.getParentFile()); return f.createNewFile(); }
public synchronized File returnDir(long fId) { File re = _F(fId, null); if (!re.exists()) Files.makeDir(re); return re; }
public File returnDir(long fId) { File f = Pools.getFileById(home, fId, null); if (!f.exists()) Files.makeDir(f); return f; }
public void clear() { Files.deleteDir(home); Files.makeDir(home); cursor = 0; }
/** * 将文件改名 * * @param src * 文件 * @param newName * 新名称 * @return 改名是否成功 */ public static boolean rename(File src, String newName) { if (src == null || newName == null) return false; if (src.exists()) { File newFile = new File(src.getParent() + "/" + newName); if (newFile.exists()) return false; Files.makeDir(newFile.getParentFile()); return src.renameTo(newFile); } return false; }
/** * 将文件移动到新的位置 * * @param src * 原始文件 * @param target * 新文件 * @return 移动是否成功 * @throws IOException */ public static boolean move(File src, File target) throws IOException { if (src == null || target == null) return false; makeDir(target.getParentFile()); if (src.isDirectory()) { src = new File(src.getCanonicalPath() + File.separator); target = new File(target.getCanonicalPath() + File.separator); } return src.renameTo(target); }
public synchronized File createDir() { File f = _F(current++, null); if (current > max) current = 0; if (f.exists()) Files.clearDir(f); else Files.makeDir(f); return f; }
/** * 传入一个目录对象,如果目录不存在,则创建目录 * * @param d * 文件目录对象 * @return 文件目录对象,以便调用者省略一行代码 */ public static File createDirIfNoExists(File d) { if (null == d) return d; if (!d.exists()) { if (!Files.makeDir(d)) { throw Lang.makeThrow("fail to create '%s', permission deny?", d.getAbsolutePath()); } } if (!d.isDirectory()) throw Lang.makeThrow("'%s' should be a directory!", d); return d; }
/** * 拷贝一个目录 * * @param src * 原始目录 * @param target * 新目录 * @return 是否拷贝成功 * @throws IOException */ public static boolean copyDir(File src, File target) throws IOException { if (src == null || target == null || !src.exists()) return false; if (!src.isDirectory()) throw new IOException(src.getAbsolutePath() + " should be a directory!"); if (!target.exists()) if (!makeDir(target)) return false; boolean re = true; File[] files = src.listFiles(); if (null != files) { for (File f : files) { if (f.isFile()) re &= copyFile(f, new File(target.getAbsolutePath() + "/" + f.getName())); else re &= copyDir(f, new File(target.getAbsolutePath() + "/" + f.getName())); } } return re; }
/** * 试图生成一个目录对象,如果文件不存在则创建它。 如果给出的 PATH 是相对路径 则会在 CLASSPATH * 中寻找,如果未找到,则会在用户主目录中创建这个目录 * * @param path * 文件路径,可以以 ~ 开头,也可以是 CLASSPATH 下面的路径 * @return 文件对象 */ public static File createDirIfNoExists(String path) { String thePath = Disks.absolute(path); if (null == thePath) thePath = Disks.normalize(path); File f = new File(thePath); if (!f.exists()) { boolean flag = Files.makeDir(f); if (!flag) { Logs.get().warnf("create filepool dir(%s) fail!!", f.getPath()); } } if (!f.isDirectory()) throw Lang.makeThrow("'%s' should be a directory or don't have permission to create it!", path); return f; }
/** * 创建新文件,如果父目录不存在,也一并创建。可接受 null 参数 * * @param f * 文件对象 * @return false,如果文件已存在。 true 创建成功 * @throws IOException */ public static boolean createNewFile(File f) throws IOException { if (null == f || f.exists()) return false; makeDir(f.getParentFile()); return f.createNewFile(); }
public void clear() { Files.deleteDir(home); Files.makeDir(home); cursor = 0; }
public synchronized File returnDir(long fId) { File re = _F(fId, null); if (!re.exists()) Files.makeDir(re); return re; }
public File returnDir(long fId) { File f = Pools.getFileById(home, fId, null); if (!f.exists()) Files.makeDir(f); return f; }
/** * 将文件移动到新的位置 * * @param src * 原始文件 * @param target * 新文件 * @return 移动是否成功 * @throws IOException */ public static boolean move(File src, File target) throws IOException { if (src == null || target == null) return false; makeDir(target.getParentFile()); if (src.isDirectory()) { src = new File(src.getCanonicalPath() + File.separator); target = new File(target.getCanonicalPath() + File.separator); } return src.renameTo(target); }
/** * 将文件改名 * * @param src * 文件 * @param newName * 新名称 * @return 改名是否成功 */ public static boolean rename(File src, String newName) { if (src == null || newName == null) return false; if (src.exists()) { File newFile = new File(src.getParent() + "/" + newName); if (newFile.exists()) return false; Files.makeDir(newFile.getParentFile()); return src.renameTo(newFile); } return false; }
public synchronized File createDir() { File f = _F(current++, null); if (current > max) current = 0; if (f.exists()) Files.clearDir(f); else Files.makeDir(f); return f; }
/** * 传入一个目录对象,如果目录不存在,则创建目录 * * @param d * 文件目录对象 * @return 文件目录对象,以便调用者省略一行代码 */ public static File createDirIfNoExists(File d) { if (null == d) return d; if (!d.exists()) { if (!Files.makeDir(d)) { throw Lang.makeThrow("fail to create '%s', permission deny?", d.getAbsolutePath()); } } if (!d.isDirectory()) throw Lang.makeThrow("'%s' should be a directory!", d); return d; }
@SuppressWarnings("deprecation") public File upload(TempFile tempFile, String savePath) throws Exception { Files.makeDir(new File(savePath)); File saveFile = new File(savePath); Files.move(tempFile.getFile(), saveFile); if (log.isDebugEnabled()) { log.debugf("save path[%s]", savePath); } return saveFile; } }
@SuppressWarnings("deprecation") public File upload(TempFile tempFile) throws Exception { String savePath = conf.get("xlsPath") + "/" + tempFile.getSubmittedFileName(); Files.makeDir(new File(conf.get("xlsPath"))); File saveFile = new File(savePath); Files.move(tempFile.getFile(), saveFile); if (log.isDebugEnabled()) { log.debugf("save path[%s]", savePath); } return saveFile; }