Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Be careful to create the FileSystem object of HDFS

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

FileSystem fs = FiileSystem.get (new URI ("hdfs://hadoop1:9000"), new Configuration ())

You can create a fs object in this way, but when you use a blank Configuration object, only the property fs.default.name is actually granted. When the accessed HDFS uses HA (multiple parameters are required to be specified at the same time), or when you need to specify other settings, there will be a problem.

Configuration conf = new Configuration ()

Conf.addResource (new Path ("conf/core-site.xml"))

Conf.addResource (new Path ("conf/hdfs-site.xml"))

FileSystem fs = FiileSystem.get (conf)

The FS created in this way is more flexible and convenient. Because it reads the settings in xml directly, you can also call the conf.set method to set a single property if necessary.

In addition, there are several forms of addResource, one of which is addResource (String fileName), and the argument passed in is the file name. This form is strongly dependent on CLASS_PATH, and the program will only look for the file name in CLASS_PATH, and it is invalid to write a path in the file name.

Another form of addResource is addResource (Path file), which does not depend on CLASS_PATH and can specify a path during new Path, whether it is debugging in program development or when the parameter files are relatively fixed at deployment time.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report