Hadoop Configuration 加载资源文件
来源:互联网 发布:淘宝网苏州虎丘牌二胡 编辑:程序博客网 时间:2024/06/03 03:30
Configuration 的loadResources()方法 (采用lazy加载)
1.解释了为什么会加载一些默认文件(*.site.xml)
2.测试了一下用file的方式去读取hdfs文件,不行
else if (name instanceof Path)中,会转换为本地文件,最后变成d:\\hdfs地址
linux下也试了一下,同样是不行的,这种方式暂时行不通,以后这样的还是用文件流的方式来读取,
因为最后都是转换InputStream流的方式来读取,然后交给Document去解析xml文件
1.解释了为什么会加载一些默认文件(*.site.xml)
2.测试了一下用file的方式去读取hdfs文件,不行
else if (name instanceof Path)中,会转换为本地文件,最后变成d:\\hdfs地址
linux下也试了一下,同样是不行的,这种方式暂时行不通,以后这样的还是用文件流的方式来读取,
因为最后都是转换InputStream流的方式来读取,然后交给Document去解析xml文件
3.addResources(Path)这个函数针对的本地文件,注释如下
file-path of resource to be added, the local filesystem is examined directly to find the resource, without referring to the classpath.
所以如果一定要用的话可以这样用
Path tmp = new Path("file:///D://shili//src//main//java//com//pangu//site.xml");
conf.addResource(tmp);
file-path of resource to be added, the local filesystem is examined directly to find the resource, without referring to the classpath.
所以如果一定要用的话可以这样用
Path tmp = new Path("file:///D://shili//src//main//java//com//pangu//site.xml");
conf.addResource(tmp);
4.对于远程HDFS上以hdfs://hdfs://yfw-0249:29000/pipeline/pets/pets_1.0/20130422/_logs/history/YFW-0337_1364622621869_job_201303301350_99243_conf.xml
采用文件流的方式来读取
以后方法调用时先读下方法注释
demo如下:
package com.pangu;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataInputStream;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;public class Java4Test {private static FSDataInputStream fsInput;/** * @param args */public static void main(String[] args) {Configuration conf = new Configuration();conf.set("fs.default.name", "hdfs://YFW-0249:29000");conf.addResource("site.xml");String target = "mapred.reduce.tasks";String path = "hdfs://yfw-0249:29000/pipeline/pets/pets_1.0/20130422/_logs/history/YFW-0337_1364622621869_job_201303301350_99243_conf.xml";Path tmp = new Path("file:///D://shili//src//main//java//com//pangu//site.xml");// ClassLoader.getSystemClassLoader().getParent() ;\try {FileSystem fs = FileSystem.get(conf);fsInput = fs.open(new Path(path));} catch (Exception e) {}/*Path tmp = new Path(path); System.out.println(tmp.toUri().toString());File file = new File(tmpPath);System.out.println(file.getAbsolutePath());if (!file.exists()) {System.out.println("test ");}*/conf.addResource(tmp);System.err.println(conf.getInt(target, 4));}}
- Hadoop Configuration 加载资源文件
- Hadoop加载自有资源文件
- commons-configuration.jar读取资源文件
- 动态加载资源文件
- spring加载资源文件
- spring加载资源文件
- 加载属性资源文件
- 加载国际化资源文件
- java加载资源文件
- ServletContext加载资源文件
- 加载资源文件
- SPRING 加载资源文件
- PropertyPlaceholderConfigurer加载资源文件
- 资源文件加载
- 加载资源文件一
- pyqt 加载资源文件
- spring 加载资源文件
- ClassPathResource加载资源文件
- jquery ajax 同步异步的执行
- 树形查询的优化
- css样式
- epoll使用
- vim全局替换命令
- Hadoop Configuration 加载资源文件
- 给年轻程序员的建议
- ORACLE中一个简单的PIVOT例子
- cocos2d-x精灵加亮及变灰效果
- html元素
- 工具使用心得和错误解决方案
- Mybatis的if test字符串比较问题
- UVaOJ110---Meta-Loopless Sorts
- showDialog()、onPrepareDialog()和onCreateDialog()的关系