Deleting Directories
Function
Delete a specified directory from the HDFS.
Files in the deleted directory will be stored in the Trash/Current folder of the directory of the current user. In the event of mis-deletion, you can restore the folder from the directory.
Example Codes
The following is a code snippet of file deletion. For complete codes, see the HdfsExample class in com.huawei.bigdata.hdfs.examples.
/** * delete the directory * * @throws java.io.IOException */ private void rmdir() throws IOException { Path destPath = new Path(DEST_PATH); if (!deletePath(destPath)) { LOG.error("failed to delete destPath " + DEST_PATH); return; } LOG.info("success to delete path " + DEST_PATH); } /** * delete file path * * @param filePath * @return * @throws java.io.IOException */ private boolean deletePath(final Path filePath) throws IOException { if (!fSystem.exists(filePath)) { return false; } // fSystem.delete(filePath, true); return fSystem.delete(filePath, true); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.