hadoop通过Configuration类来保存配置信息
1、通过Configuration.addResource()来加载配置文件
2、通过Configuration.get***()来获取配置属性
1、创建一个新的Configuration实例时,会加载core-default.xml与core-site.xml,若还有其它配置,则调用addResource()继续添加。
package org.jediael.hadoopdemo;
import org.apache.hadoop.conf.Configuration;
public class ConfigurationDemo {
public static void main(String[] args){
Configuration conf = new Configuration();
//conf.addResource("/opt/jediael/hadoop-1.2.1/conf/core-site.xml");
Configuration.addDefaultResource("mapred-default.xml");
//System.out.println(conf.get("fs.default.name"));
System.out.println(conf.get("hadoop.tmp.dir"));
System.out.println(conf.get("io.sort.mb"));
}
}
输出结果为:
www:Downloads liaoliuqing$ had