List of usage examples for java.io File delete
public boolean delete()
From source file:brut.util.OS.java
public static void rmfile(String file) throws BrutException { File del = new File(file); del.delete(); }
From source file:Main.java
public static void deleteDirectory(File f) { if (f.isDirectory()) { for (File c : f.listFiles()) deleteDirectory(c);/*from w w w.ja va 2s. c om*/ } f.delete(); }
From source file:com.theminequest.MineQuest.Quest.QuestWorldManip.java
public static World copyWorld(World w) throws IOException { String newname;/* w ww. ja v a2 s . com*/ File newdirectory; do { newname = "mqinstance_" + randGen.nextLong(); newdirectory = new File(newname); } while (newdirectory.exists()); FileUtils.copyDirectory(w.getWorldFolder(), newdirectory); File uid = new File(newdirectory + File.separator + "uid.dat"); if (uid.exists()) uid.delete(); WorldCreator tmp = new WorldCreator(newname); tmp.copy(w); return Bukkit.createWorld(tmp); }
From source file:edu.brandeis.wisedb.scheduler.experiments.SkewDistributionExperiment.java
public static void calculateBurn(int samples) throws Exception { TightenableSLA sla = PercentSLA.nintyTenSLA(); //TightenableSLA sla = new SimpleLatencyModelSLA(9 * 60 * 1000, 1); //TightenableSLA sla = PerQuerySLA.getLatencyTimesN(2.0); //TightenableSLA sla = new AverageLatencyModelSLA(7 * 60 * 1000, 1); QueryTimePredictor qtp = new QueryTimePredictor(); File f = new File("distSkew.csv"); if (f.exists()) f.delete(); try (Trainer t = new Trainer("distSkew.csv", sla)) { t.train(2000, 12);//from w ww.ja va 2 s . c o m } DTSearcher dt = new DTSearcher("distSkew.csv", qtp, sla); AStarGraphSearch astar = new AStarGraphSearch(new UnassignedQueryTimeHeuristic(qtp), sla, qtp); //FirstFitDecreasingGraphSearch astar = new FirstFitDecreasingGraphSearch(sla, qtp); ChiSquareTest cst = new ChiSquareTest(); ChiSquaredDistribution cqd = new ChiSquaredDistribution(qtp.QUERY_TYPES.length - 1); double[] expceted = Arrays.stream(qtp.QUERY_TYPES).mapToDouble(i -> 20.0 / (qtp.QUERY_TYPES.length)) .toArray(); System.out.println("Chi\tDT\tOpt"); for (int i = 0; i < samples; i++) { Set<ModelQuery> smp = ModelWorkloadGenerator.randomQueries(20); // reject samples that don't have at least one of each query type long repr = smp.stream().mapToInt(q -> q.getType()).distinct().count(); if (repr != qtp.QUERY_TYPES.length) { i--; continue; } Map<Integer, List<ModelQuery>> groups = smp.stream().collect(Collectors.groupingBy(q -> q.getType())); long obs[] = Arrays.stream(qtp.QUERY_TYPES).mapToLong(v -> groups.get(v).size()).toArray(); double chi = cst.chiSquare(expceted, obs); chi = cqd.cumulativeProbability(chi); Cost dtCost = dt.getCostForQueries(smp, sla); Cost optCost = astar.getCostForQueries(smp, sla); System.out.println(chi + "\t" + dtCost.getTotalCost() + "\t" + optCost.getTotalCost()); } }
From source file:Main.java
public static boolean deleteFileOrDir(File path) { if (path == null || !path.exists()) { return true; }//from w ww . ja va2 s . com if (path.isFile()) { return path.delete(); } File[] files = path.listFiles(); if (files != null) { for (File file : files) { deleteFileOrDir(file); } } return path.delete(); }
From source file:Main.java
public static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isDirectory()) { String[] listfile = newPath.list(); // delete all files within the specified directory and then // delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); }//from www.j a v a2s . co m newPath.delete(); Log.i("DirectoryManager deleteDirectory", fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }
From source file:Main.java
public static boolean deleteSpicificFile(String filePath) { if (!isEmpty(filePath) && isSDCardAvailable()) { try {//from www . j av a 2s .c o m File file = new File(filePath); if (file.exists() && file.isFile()) { return file.delete(); } } catch (Exception e) { if (e != null && isNotEmpty(e.getMessage())) { Log.e("@@@", e.getMessage()); } } } return false; }
From source file:Main.java
public static boolean deleteFile(String path) { try {/*from w w w . j a va2s . co m*/ File fileToDelete = new File(path); if (fileToDelete.exists()) { fileToDelete.delete(); } } catch (Exception e) { return false; } return true; }
From source file:Main.java
static File rename(File file, String newName) { File newFile = new File(file.getParent(), newName); if (!newFile.equals(file)) { if (newFile.exists()) { if (newFile.delete()) { Log.d("FileUtil", "Delete old " + newName + " file"); }//w ww . j ava 2 s . c om } if (file.renameTo(newFile)) { Log.d("FileUtil", "Rename file to " + newName); } } return newFile; }
From source file:Main.java
public static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isDirectory()) { String[] listfile = newPath.list(); // delete all files within the specified directory and then // delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); }// ww w . j a va 2s .c o m newPath.delete(); Log.d(TAG, "DirectoryManager deleteDirectory" + fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }