/** * Create the directory and all required parent directories. * * @param dir the directory name */ public static void createDirectories(String dir) { if (dir != null) { if (exists(dir)) { if (!isDirectory(dir)) { // this will fail createDirectory(dir); } } else { String parent = getParent(dir); createDirectories(parent); createDirectory(dir); } } }
/** * Delete a directory or file and all subdirectories and files. * * @param path the path * @param tryOnly whether errors should be ignored */ public static void deleteRecursive(String path, boolean tryOnly) { if (exists(path)) { if (isDirectory(path)) { for (String s : newDirectoryStream(path)) { deleteRecursive(s, tryOnly); } } if (tryOnly) { tryDelete(path); } else { delete(path); } } }
private static synchronized void renameFile( String oldName, String newName) { FileUtils.move(oldName, newName); }
/** * Load a properties object from a file. * * @param fileName the name of the properties file * @return the properties object */ public static synchronized SortedProperties loadProperties(String fileName) throws IOException { SortedProperties prop = new SortedProperties(); if (FileUtils.exists(fileName)) { InputStream in = null; try { in = FileUtils.newInputStream(fileName); prop.load(in); } finally { if (in != null) { in.close(); } } } return prop; }
if (packageName != null) { dir = new File(dir, packageName.replace('.', '/')); FileUtils.createDirectories(dir.getAbsolutePath()); OutputStream f = FileUtils.newOutputStream(javaFile.getAbsolutePath(), false); Writer out = IOUtils.getBufferedWriter(f); classFile.delete();
@Override public void close() { if (fileName != null) { FileUtils.delete(fileName); } }
@Override public OutputStream newOutputStream(boolean append) throws IOException { try { File file = new File(name); File parent = file.getParentFile(); if (parent != null) { FileUtils.createDirectories(parent.getAbsolutePath()); } FileOutputStream out = new FileOutputStream(name, append); IOUtils.trace("openFileOutputStream", name, out); return out; } catch (IOException e) { freeMemoryAndFinalize(); return new FileOutputStream(name); } }
private static String createTempLobFileName() throws IOException { String path = getDatabasePath(); if (path.length() == 0) { path = SysProperties.PREFIX_TEMP_FILE; } return FileUtils.createTempFile(path, Constants.SUFFIX_TEMP_FILE, true, true); }
for (String name : list) { if (name.endsWith(Constants.SUFFIX_DB_FILE)) { name = FileUtils.getName(name); String n = name.substring(0, name.indexOf('.')); int id;
@Override public void close() { if (fileName != null) { FileUtils.delete(fileName); } }
dir = new File(fileName).getAbsoluteFile().getParentFile(); FileUtils.createDirectories(dir.getAbsolutePath()); while (true) { File f = new File(dir, prefix + getNextTempFileNamePart(false) + suffix);
private static synchronized void deleteFile( String fileName) { FileUtils.delete(fileName); }