List of usage examples for java.io File delete
public boolean delete()
From source file:com.linkedin.restli.tools.idlgen.TestRestLiResourceModelExporter.java
public static void rmdir(File dir) { if (dir.listFiles() != null) { for (File f : dir.listFiles()) { f.delete(); }// w w w. j a v a2s . c om } dir.delete(); }
From source file:com.wordnik.swagger.codegen.util.FileUtil.java
/** * Deleet all the files from the specified location * @param directoryLocation//w w w .jav a 2s . c o m */ public static void clearFolder(String directoryLocation) { File fDir = new File(directoryLocation); File[] files = fDir.listFiles(); if (files != null) { for (File aFile : files) { aFile.delete(); } } }
From source file:com.zyz.mobile.file.FileClipboard.java
/** * Delete the specified file.// w w w . j a v a 2 s . c om * * @param file the file to be deleted */ public static void deleteFile(File file) throws IOException { if (file.isFile()) { file.delete(); } else { FileUtils.deleteDirectory(file); } }
From source file:jeeves.utils.IO.java
public static void delete(File file, boolean throwException, String loggerModule) { if (!file.delete() && file.exists()) { if (throwException) { throw new RuntimeException("Unable to delete " + file.getAbsolutePath()); } else {/*from www. ja v a 2 s. co m*/ Log.warning(loggerModule, "Unable to delete " + file.getAbsolutePath()); } } }
From source file:Main.java
public static void rename(File from, File to, boolean delete) { if (!from.exists()) { return;/*from ww w . java 2 s . c o m*/ } boolean isRename = false; if (to.exists()) { if (delete) { to.delete(); isRename = true; } else { isRename = false; } } else { isRename = true; } if (isRename) { File parent = to.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } from.renameTo(to); } }
From source file:com.adaptris.core.LogHandlerTest.java
public static void ensureDirectory(File dirOrFile) { if (dirOrFile.isFile()) { dirOrFile.delete(); }//from ww w.j ava 2s. co m dirOrFile.mkdirs(); }
From source file:Main.java
/** * Save jpeg image with background color * @param strFileName Save file path/*from ww w.j a va 2 s . c o m*/ * @param bitmap Input bitmap * @param nQuality Jpeg quality for saving * @param nBackgroundColor background color * @return whether success or not */ public static boolean saveBitmapJPEGWithBackgroundColor(String strFileName, Bitmap bitmap, int nQuality, int nBackgroundColor) { boolean bSuccess1 = false; boolean bSuccess2 = false; boolean bSuccess3; File saveFile = new File(strFileName); if (saveFile.exists()) { if (!saveFile.delete()) return false; } int nA = (nBackgroundColor >> 24) & 0xff; // If Background color alpha is 0, Background color substitutes as white if (nA == 0) nBackgroundColor = 0xFFFFFFFF; Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(newBitmap); canvas.drawColor(nBackgroundColor); canvas.drawBitmap(bitmap, rect, rect, new Paint()); // Quality limitation min/max if (nQuality < 10) nQuality = 10; else if (nQuality > 100) nQuality = 100; OutputStream out = null; try { bSuccess1 = saveFile.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); } try { out = new FileOutputStream(saveFile); bSuccess2 = newBitmap.compress(CompressFormat.JPEG, nQuality, out); } catch (Exception e) { e.printStackTrace(); } try { if (out != null) { out.flush(); out.close(); bSuccess3 = true; } else bSuccess3 = false; } catch (IOException e) { e.printStackTrace(); bSuccess3 = false; } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } return (bSuccess1 && bSuccess2 && bSuccess3); }
From source file:de.bund.bfr.pmfml.file.CombineArchiveUtil.java
/** * Removes previous CombineArchive if it exists *//*from ww w . j a v a 2s . c om*/ public static void removeExistentFile(final String filename) { final File tmpFile = new File(filename); if (tmpFile.exists()) { tmpFile.delete(); } }
From source file:c3.ops.priam.utils.SystemUtils.java
public static void createDirs(String location) { File dirFile = new File(location); if (dirFile.exists() && dirFile.isFile()) { dirFile.delete(); dirFile.mkdirs();/*from ww w . ja v a2s . c om*/ } else if (!dirFile.exists()) dirFile.mkdirs(); }
From source file:Main.java
private static void SaveCustomerFile(Document CustomerDoc, JFrame mainFrame) { try {// ww w . j a v a 2 s . co m TransformerFactory Factory = TransformerFactory.newInstance(); Transformer Trans = Factory.newTransformer(); DOMSource source = new DOMSource(CustomerDoc); File f = new File("."); String FilePath = f.getAbsoluteFile().getParent() + "\\Customers.xml"; f = new File(FilePath); if (f.exists()) { f.delete(); } StreamResult Result = new StreamResult(f); Trans.setOutputProperty(OutputKeys.INDENT, "yes"); Trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "7"); Trans.transform(source, Result); } catch (TransformerException ex) { System.out.println(ex.getMessage()); JOptionPane.showMessageDialog(mainFrame, "There Was an Error Saving The File. Please Restart the Application."); System.exit(1); } }