Deleting an HDFS File
Function Description
Delete a specified file or folder from HDFS.
![](https://support.huaweicloud.com/intl/en-us/devg-mrs/public_sys-resources/note_3.0-en-us.png)
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); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot