Deleting a File
Function
Delete a file from the Hadoop distributed file system (HDFS).
![](https://support.huaweicloud.com/eu/devg-lts-mrs/public_sys-resources/note_3.0-en-us.png)
Exercise caution when you delete files because the deletion is irreversible.
Example Codes
The following is code snippets. For complete codes, see the HdfsExample class in com.huawei.bigdata.hdfs.examples.
/** * Delete a file. * * @throws java.io.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
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.