HDFS Application Development Approach
Scenario
Service operation objects of HDFS are files. File operations in example codes include creating a folder, writing data into a file, appending data to a file, reading data from a file, and deleting a file or folder. HDFS also supports other services including setting file permission. You can learn how to perform other operations on HDFS after learning the example codes in this chapter.
The example codes are described in the following order:
- Initializing the HDFS.
- Creating directories.
- Writing data into a file.
- Appending data to a file.
- Reading data from a file.
- Deleting a file.
- Deleting directories.
- Multi-thread tasks.
- Setting storage policies.
- Colocation.
Development Guideline
According to the previous scenario description, the following provides the basic operations for HDFS files with read, write, and delete operations on the /user/hdfs-examples/test.txt file as an example:
- Pass the security certification.
- Create a FileSystem object: fSystem.
- Call the mkdir interface in fSystem to create a directory.
- Call the create interface in fSystem to create an FSDataOutputStream object: out. Use the write method to write data into the object out.
- Call the append interface in fSystem to create an FSDataOutputStream object: out. Use the write method to append data into the object out.
- Call the open interface in fSystem to create an FSDataInputStream object: in. Use the read method to read files of the object in.
- Call the delete interface in fSystem to delete the file.
- Call the delete interface in fSystem to delete the folder.
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