Code example for File

Methods: createNewFile, exists, getAbsolutePath, getParentFile

0
	 * 
	 * @param file the file to be created 
	 * @throws IOException 
	 */ 
	public static void createFileAndParentDirectoriesIfNecessary(File file) throws IOException {
        if(!file.exists()) {
            File parent = file.getParentFile();
            parent.mkdirs();
 
            file.createNewFile();
            Runtime.getRuntime().exec("chmod 755 " + file.getAbsolutePath());
        } 
	} 
 
	/** 
	 * Utilty to process a file line by line, replacing strings with values 
	 * 
	 * @param fileName the name of the file to process 
	 * @param replacements array of 2 element string arrays, 0 is string to match, 1 is replacement 
	 * @throws IOException 
	 */