Updated on 2022-06-01 GMT+08:00

Deleting a File

Function Description

Delete a specified file or folder from HDFS.

The deleted file or folder is stored in the .Trash/Current folder in the current user directory. If the file is deleted by mistake, you can restore it from this folder.

Sample Code

The following provides code snippets for deleting a file. For complete codes, see the HdfsMain class in com.huawei.bigdata.hdfs.examples.

  /**
   * Delete a file.
   *
   * @throws IOException
   */
  private void delete() throws IOException {
    Path beDeletedPath = new Path(DEST_PATH + File.separator + FILE_NAME);
    fSystem.deleteOnExit(beDeletedPath);
    System.out.println("succee to delete the file " + DEST_PATH
        + File.separator + FILE_NAME);
  }