Help Center/
MapReduce Service/
Developer Guide (Normal_3.x)/
HDFS Development Guide (Security Mode)/
Developing an HDFS Application/
Creating an HDFS Directories
Updated on 2024-10-23 GMT+08:00
Creating an HDFS Directories
Function
Process of creating a directory:
- Call the exists method of the FileSystem instance to check whether the directory exists.
- If yes, the method stops.
- If no, call the mkdirs method in the FileSystem instance to create a directory.
Example Codes
The following is a code snippet. For complete codes, see the HdfsExample class in com.huawei.bigdata.hdfs.examples.
/** * Create a directory. * * @throws java.io.IOException */ private void mkdir() throws IOException { Path destPath = new Path(DEST_PATH); if (!createPath(destPath)) {???LOG.error("failed to create destPath " + DEST_PATH); return; } LOG.info("success to create path " + DEST_PATH); } /** * create file path * * @param filePath * @return * @throws java.io.IOException */ private boolean createPath(final Path filePath) throws IOException { if (!fSystem.exists(filePath)) { fSystem.mkdirs(filePath); } return true; }
Parent topic: Developing an HDFS Application
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.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot