package edu.usc.glidein.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class IOUtil
{
	/**
	 * Read the contents of a file
	 * @param f The file to read
	 * @return The entire contents of the file
	 */
	public static String read(File file) throws IOException
	{
		StringBuffer buff = new StringBuffer();
		BufferedReader reader = new BufferedReader(new FileReader(file));
		try
		{
			String line = null;
			int i = 0;
			while((line = reader.readLine()) != null)
			{
				if(i>0) buff.append("\n");
				buff.append(line);
				i++;
			}
		}
		finally
		{
			reader.close();
		}
		return buff.toString();
	}
	
	/**
	 * Write a string to a file
	 * @param output The string to write
	 * @param file The file to write to
	 * @throws IOException If there is a problem writing the file
	 */
	public static void write(String output, File file) throws IOException
	{
		BufferedWriter writer = new BufferedWriter(new FileWriter(file));
		try
		{
			writer.write(output);
		}
		finally
		{
			writer.close();
		}
	}
}

@@ -1133,10 +1133,540 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09/**%0A%09 * Remove a directory and all files and sub-directories%0A%09 * @param dir The directory to remove%0A%09 * @return true if everything was deleted, false otherwise%0A%09 */%0A%09public static boolean rmdirs(File dir) %0A%09%7B%0A%09%09if (dir.isFile()) %7B%0A%09%09%09return dir.delete();%0A%09%09%7D else if (dir.isDirectory()) %7B%0A%09%09%09boolean result = true;%0A%09%09%09File%5B%5D fds = dir.listFiles();%0A%09%09%09for(File fd : fds) %7B%0A%09%09%09%09result = result && rmdirs(fd);%0A%09%09%09%7D%0A%09%09%09return result && dir.delete();%0A%09%09%7D else %7B%0A%09%09%09throw new IllegalStateException(%22Not a file or directory%22);%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

Add rmdirs