Example #1
0
  public static void clearFolder(File folder) {
    if (folder.exists()) {
      for (File child : folder.listFiles()) {
        if (child.isDirectory())
          clearFolder(child);

        if (!child.delete())
          throw new RuntimeException("Cannot delete " + child);
      }
    }
  }
Example #2
0
 /**
  * Returns the system temporary folder, e.g. /tmp
  */
 public static File tmp() {
   try {
     return File.createTempFile("h2o", null).getParentFile();
   } catch( IOException e ) {
     throw new RuntimeException(e);
   }
 }
Example #3
0
 public static File writeFile(String content) {
   try {
     return writeFile(File.createTempFile("h2o", null), content);
   } catch( IOException e ) {
     throw Log.errRTExcept(e);
   }
 }
Example #4
0
 public static String readFile(File file) {
   FileReader r = null;
   try {
     r = new FileReader(file);
     char[] data = new char[(int) file.length()];
     r.read(data);
     return new String(data);
   } catch(IOException e) {
     throw Log.errRTExcept(e);
   } finally {
     close(r);
   }
 }