1、删除文件
/** * delete file * 删除文件 * @param fileName * @return */ private boolean deleteDir(String fileName) { boolean flag = false; File file = new File(fileName); if(file.exists()){ flag = delFile(file); } return flag; } /** * delete file * 删除文件 * @param fileName * @return */ private boolean delFile(File file) { if (!file.exists()) { return false; } if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { delFile(f); } } return file.delete(); }
2、获取项目根路径
/** * 获取路径 * @return */ public String getWebRoot() { String realUrl = getClass().getProtectionDomain().getCodeSource() .getLocation().getPath(); String newUrl = ""; if (realUrl.contains("/WEB-INF/")) { newUrl = realUrl.substring(0, realUrl.lastIndexOf("WEB-INF/")); } realUrl = newUrl.replace("%20", " ");//此路径不兼容jboss return realUrl; }