On this page

Deleting a File

Updated on 2022-09-14 GMT+08:00

Function

Delete a file from the Hadoop distributed file system (HDFS).

NOTE:

Exercise caution when you delete files because the deletion is irreversible.

Example Codes

The following is code snippets. 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);
    if (fSystem.delete(beDeletedPath, true)) {
        LOG.info("success to delete the file " + DEST_PATH + File.separator + FILE_NAME);
    } else {
        LOG.warn("failed to delete the file " + DEST_PATH + File.separator + FILE_NAME);
    }
}
Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback