/** * Given a directory, returns a set of strings which are the paths to all elements * within the directory. This process recurses through all sub-directories. * @param dir The directory to be traversed * @param includeDirectories If set, the name of the paths to directories are included * in the result. * @return A set of paths to all elements in the given directory */ static public Set<String> getDescendantPathNames(File dir, boolean includeDirectories) { Set<String> paths = new HashSet<String>(); if( dir.exists() && dir.isDirectory() ) { String[] names = dir.list(); for(String name : names){ File child = new File(dir,name); getPathNames(child, paths, null, includeDirectories); } } return paths; }
/** * Given a directory, removes all the content found in the directory. * @param dir The directory to be emptied * @throws Exception */ static public void emptyDirectory(File dir) throws Exception { String[] fileNames = dir.list(); if( null != fileNames ) { for(String fileName : fileNames){ File file = new File(dir,fileName); if( file.isDirectory() ) { emptyDirectory(file); } boolean deleted = false; try { deleted = file.delete(); } catch(Exception e) { throw new Exception("Unable to delete: "+file.getAbsolutePath(),e); } if( !deleted ){ throw new Exception("Unable to delete: "+file.getAbsolutePath()); } } } } }
String val = (String)valObj; key = saveConvert(key, true); val = saveConvert(val, false); bw.write(key + "=" + val); bw.newLine();
fos = new FileOutputStream(installPropFile); OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8"); PropertiesWriter propWriter = new PropertiesWriter(osw); propWriter.write(publicProps); fos = new FileOutputStream(sensitivePropFile); OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8"); PropertiesWriter propWriter = new PropertiesWriter(osw); propWriter.write(sensitiveProps);
File child = new File(currentParent, name); if( false == child.exists() ){ Files.createDirectory(child); } else if( false == child.isDirectory() ) { throw new Exception("Attachment path is not a directory: "+child.getAbsolutePath());
File childTarget = new File(target,childName); copy(childSource,childTarget);
Files.createDirectory(dumpDir);
static private void getPathNames(File dir, Set<String> paths, String prefix, boolean includeDirectories) { if( dir.exists() ) { if( dir.isFile() ){ String path = dir.getName(); if( null != prefix ) { path = prefix + File.pathSeparator + dir.getName(); } paths.add(path); } else if( dir.isDirectory() ) { String dirPath = dir.getName(); if( null != prefix ) { dirPath = prefix + File.pathSeparator + dir.getName(); } if( includeDirectories ){ paths.add(dirPath); } // Children String[] names = dir.list(); for(String name : names){ File child = new File(dir,name); getPathNames(child, paths, dirPath, includeDirectories); } } } }
Files.createDirectory(attachmentDir);