Help Center/ MapReduce Service/ Developer Guide (Normal_3.x)/ HDFS Development Guide (Security Mode)/ Developing an HDFS Application/ Creating an HDFS Directories
Updated on 2025-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
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.