Help Center/
MapReduce Service/
Developer Guide (LTS)/
HDFS Development Guide (Normal Mode)/
Developing the Project/
Declare the Example Codes/
Creating Directories
Updated on 2022-07-11 GMT+08:00
Creating 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: Declare the Example Codes
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