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); } } }
/** * 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); } }
public static File writeFile(String content) { try { return writeFile(File.createTempFile("h2o", null), content); } catch( IOException e ) { throw Log.errRTExcept(e); } }
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); } }