List of usage examples for java.io File delete
public boolean delete()
From source file:Main.java
/** * Create a temporary file that will be deleted after a specified number of seconds. * The file will be deleted regardless of whether it is still used or not, * so be sure to specify a sufficiently large value. * * @param lifetimeInSeconds the number of seconds after which the file will be * deleted -- e.g., 3600 means that the file will be deleted one hour after creation. * @return the File that was created.// w ww . j av a 2s.c om * @throws IOException */ public static File createSelfDeletingTempFile(int lifetimeInSeconds) throws IOException { final File f = File.createTempFile("mary", "temp"); maintenanceTimer.schedule(new TimerTask() { @Override public void run() { f.delete(); } }, lifetimeInSeconds * 1000l); return f; }
From source file:org.wso2.am.integration.services.jaxrs.peoplesample.Starter.java
private static File createBaseDirectory() throws IOException { final File base = File.createTempFile("tmp-", "", new File("/home/dharshana/reaserch/jetty/jetty2/src/main/resources")); if (!base.delete()) { throw new IOException("Cannot (re)create base folder: " + base.getAbsolutePath()); }/*from w ww . j a v a 2 s .co m*/ if (!base.mkdir()) { throw new IOException("Cannot create base folder: " + base.getAbsolutePath()); } return base; }
From source file:com.fun.util.TesseractUtil.java
/** * url/*from w w w . j a v a 2 s .c om*/ * @param url * @return * @throws IOException */ public static String recognize(URL url) throws IOException { File tmpFile = getFileFromUrl(url); String result = recognize(tmpFile); tmpFile.delete(); return result; }
From source file:io.cloudex.framework.utils.FileUtils.java
/** * Delete the file with the provided string * @param filename - the name of the file to delete * @return/* ww w . ja v a 2 s . c o m*/ */ public static boolean deleteFile(String filename) { File file = new File(filename); return file.delete(); }
From source file:net.adamcin.oakpal.testing.TestPackageUtil.java
public static File prepareTestPackage(final String filename) throws IOException { File file = new File(testPackagesRoot, filename); if (file.exists()) { file.delete(); }/*w ww. j a v a 2s.c o m*/ try (InputStream is = TestPackageUtil.class.getResourceAsStream(testPackagesSrc + filename); FileOutputStream fos = new FileOutputStream(file)) { IOUtils.copy(is, fos); } return file; }
From source file:Main.java
/** * Delete file or folder./* w ww . j a va 2 s. co m*/ * * @param file file. * @return is succeed. * @see #delFileOrFolder(String) */ @SuppressWarnings("ResultOfMethodCallIgnored") public static boolean delFileOrFolder(File file) { if (file == null || !file.exists()) { // do nothing } else if (file.isFile()) file.delete(); else if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) for (File sonFile : files) delFileOrFolder(sonFile); file.delete(); } return true; }
From source file:Main.java
@SuppressWarnings("WeakerAccess") public static boolean cleanDir(File dir) { if (dir == null || !dir.exists() || !dir.isDirectory()) { return true; }/* w w w .java 2s . com*/ File[] files = dir.listFiles(); boolean cleanSuccess = true; if (files != null) { for (File tempFile : files) { if (tempFile.isDirectory()) { cleanSuccess &= cleanDir(tempFile); } cleanSuccess &= tempFile.delete(); } } return cleanSuccess; }
From source file:Main.java
/** * Creates a temporary file for storing a photo that will be taken with the * camera./*from w w w.j a va2s . com*/ * * @param context * the application's context * @return a Uri that points to the file */ public static Uri getPhotoUri(Context context) { File photo; try { // place where to store camera taken picture photo = createTemporaryFile("picture", ".jpg", context); photo.delete(); } catch (Exception e) { Log.v(TAG, "Can't create file to take picture!"); return null; } Uri mImageUri = Uri.fromFile(photo); return mImageUri; }
From source file:com.adaptris.util.datastore.TestSimpleDataStore.java
private static Properties createProperties() throws IOException { Properties sp = new Properties(); File dataFile = File.createTempFile("junitsds", ".dat"); File lockFile = File.createTempFile("junitsds", ".lock"); dataFile.delete(); lockFile.delete();//w w w. j a va 2 s .c o m sp.setProperty(SimpleDataStore.FILE_PROPERTY, dataFile.getCanonicalPath()); sp.setProperty(SimpleDataStore.LOCK_PROPERTY, lockFile.getCanonicalPath()); sp.setProperty(SimpleDataStore.MAXLOCK_PROPERTY, "10"); return sp; }
From source file:Main.java
public static boolean deleteFile(String path) { if (TextUtils.isEmpty(path)) { return true; }//from ww w . j a v a 2s.co m File file = new File(path); if (!file.exists()) { return true; } if (file.isFile()) { return file.delete(); } if (!file.isDirectory()) { return false; } for (File f : file.listFiles()) { if (f.isFile()) { f.delete(); } else if (f.isDirectory()) { deleteFile(f.getAbsolutePath()); } } return file.delete(); }