Tabnine Logo
File.delete
Code IndexAdd Tabnine to your IDE (free)

How to use
delete
method
in
java.io.File

Best Java code snippets using java.io.File.delete (Showing top 20 results out of 64,872)

Refine searchRefine arrow

  • File.<init>
  • File.exists
  • File.getAbsolutePath
  • FileOutputStream.<init>
  • File.isDirectory
  • File.listFiles
  • File.mkdirs
origin: square/okhttp

@Override public void delete(File file) throws IOException {
 // If delete() fails, make sure it's because the file didn't exist!
 if (!file.delete() && file.exists()) {
  throw new IOException("failed to delete " + file);
 }
}
origin: hankcs/HanLP

/**
 * 删除本地文件
 * @param path
 * @return
 */
public static boolean deleteFile(String path)
{
  return new File(path).delete();
}
origin: Tencent/tinker

public static final boolean deleteFile(String filePath) {
  if (filePath == null) {
    return true;
  }
  File file = new File(filePath);
  if (file.exists()) {
    return file.delete();
  }
  return true;
}
origin: voldemort/voldemort

private File getVersionDirectory() {
  File versionDir = new File(this.directory, VERSION_DIRECTORY);
  if(!versionDir.exists() || !versionDir.isDirectory()) {
    versionDir.delete();
    versionDir.mkdirs();
  }
  return versionDir;
}
origin: libgdx/libgdx

static private boolean deleteDirectory (File file) {
  if (file.exists()) {
    File[] files = file.listFiles();
    if (files != null) {
      for (int i = 0, n = files.length; i < n; i++) {
        if (files[i].isDirectory())
          deleteDirectory(files[i]);
        else
          files[i].delete();
      }
    }
  }
  return file.delete();
}
origin: stackoverflow.com

protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  switch (requestCode) {
    case GlobalConstants.IMAGE_CAPTURE:
      Uri u;
      if (hasImageCaptureBug()) {
        File fi = new File("/sdcard/tmp");
        try {
          u = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), fi.getAbsolutePath(), null, null));
          if (!fi.delete()) {
            Log.i("logMarker", "Failed to delete " + fi);
          }
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        }
      } else {
       u = intent.getData();
     }
 }
origin: gocd/gocd

private void deleteLockFile() {
  if (touchLoop == null) {
    //I haven't got the lock
    return;
  }
  if (!lockFile.exists()) {
    LOG.warn("No lock file found at {}", lockFile.getAbsolutePath());
    return;
  }
  if (!lockFile.delete()) {
    LOG.error("Unable to delete lock file at {}", lockFile.getAbsolutePath());
  }
}
origin: jenkinsci/jenkins

    @Override
    public Void invoke(File f, VirtualChannel channel) throws IOException {
      // JENKINS-16846: if f.getName() is the same as one of the files/directories in f,
      // then the rename op will fail
      File tmp = new File(f.getAbsolutePath()+".__rename");
      if (!f.renameTo(tmp))
        throw new IOException("Failed to rename "+f+" to "+tmp);
      File t = new File(target.getRemote());
      for(File child : reading(tmp).listFiles()) {
        File target = new File(t, child.getName());
        if(!stating(child).renameTo(creating(target)))
          throw new IOException("Failed to rename "+child+" to "+target);
      }
      deleting(tmp).delete();
      return null;
    }
}
origin: androidannotations/androidannotations

private void deleteDirectoryRecursively(File directory) {
  File[] childs = directory.listFiles();
  if (childs != null) {
    for (File file : childs) {
      if (file.isDirectory()) {
        deleteDirectoryRecursively(file);
      } else {
        file.delete();
      }
    }
  }
  directory.delete();
}
origin: stackoverflow.com

 File dir = new File(Environment.getExternalStorageDirectory()+"Dir_name_here"); 
if (dir.isDirectory()) 
{
  String[] children = dir.list();
  for (int i = 0; i < children.length; i++)
  {
    new File(dir, children[i]).delete();
  }
}
origin: commons-io/commons-io

void openOutputStream_noParent(final boolean createFile) throws Exception {
  final File file = new File("test.txt");
  assertNull(file.getParentFile());
  try {
    if (createFile) {
      TestUtils.createLineBasedFile(file, new String[]{"Hello"});
    }
    try (FileOutputStream out = FileUtils.openOutputStream(file)) {
      out.write(0);
    }
    assertTrue(file.exists());
  } finally {
    if (!file.delete()) {
      file.deleteOnExit();
    }
  }
}
origin: stackoverflow.com

 public static File createTempDirectory()
  throws IOException
{
  final File temp;

  temp = File.createTempFile("temp", Long.toString(System.nanoTime()));

  if(!(temp.delete()))
  {
    throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
  }

  if(!(temp.mkdir()))
  {
    throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
  }

  return (temp);
}
origin: skylot/jadx

  private Object test(Object obj) {
    File file = new File("r");
    FileOutputStream output = null;
    try {
      output = new FileOutputStream(file);
      if (obj.equals("a")) {
        return new Object();
      } else {
        return null;
      }
    } catch (IOException e) {
      System.out.println("Exception");
      return null;
    } finally {
      if (output != null) {
        try {
          output.close();
        } catch (IOException e) {
          // Ignored
        }
      }
      file.delete();
    }
  }
}
origin: apache/flink

protected static void deleteRecursively(File f) throws IOException {
  if (f.isDirectory()) {
    FileUtils.deleteDirectory(f);
  } else if (!f.delete()) {
    System.err.println("Failed to delete file " + f.getAbsolutePath());
  }
}
origin: facebook/stetho

public void cleanupFiles() {
 for (File file : mContext.getFilesDir().listFiles()) {
  if (file.getName().startsWith(FILENAME_PREFIX)) {
   if (!file.delete()) {
    LogRedirector.w(TAG, "Failed to delete " + file.getAbsolutePath());
   }
  }
 }
 LogRedirector.i(TAG, "Cleaned up temporary network files.");
}
origin: facebook/stetho

private static void truncateAndDeleteFile(File file) throws IOException {
 FileOutputStream out = new FileOutputStream(file);
 out.close();
 if (!file.delete()) {
  throw new IOException("Failed to delete " + file);
 }
}
origin: apache/zookeeper

@Test
public void testValidateFileInputDirectory() throws Exception {
  File file = File.createTempFile("test", ".junit", testData);
  file.deleteOnExit();
  // delete file, as we need directory not file
  file.delete();
  file.mkdir();
  String absolutePath = file.getAbsolutePath();
  String error = ZKUtil.validateFileInput(absolutePath);
  assertNotNull(error);
  String expectedMessage = "'" + absolutePath + "' is a direcory. it must be a file.";
  assertEquals(expectedMessage, error);
}
origin: voldemort/voldemort

private File getTempDirectory() {
  File tempDir = new File(this.directory, TEMP_DIRECTORY);
  if(!tempDir.exists() || !tempDir.isDirectory()) {
    tempDir.delete();
    tempDir.mkdirs();
  }
  return tempDir;
}
origin: libgdx/libgdx

static private boolean deleteDirectory (File file) {
  if (file.exists()) {
    File[] files = file.listFiles();
    if (files != null) {
      for (int i = 0, n = files.length; i < n; i++) {
        if (files[i].isDirectory())
          deleteDirectory(files[i]);
        else
          files[i].delete();
      }
    }
  }
  return file.delete();
}
origin: xuxueli/xxl-job

public static void deleteFile(String fileName) {
  // file
  File file = new File(fileName);
  if (file.exists()) {
    file.delete();
  }
}
java.ioFiledelete

Javadoc

Deletes this file. Directories must be empty before they will be deleted.

Note that this method does not throw IOException on failure. Callers must check the return value.

Popular methods of File

  • <init>
    Creates a new File instance by converting the givenfile: URI into an abstract pathname. The exact fo
  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • isDirectory
  • mkdirs
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • toURI
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • runOnUiThread (Activity)
  • getSharedPreferences (Context)
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now