`
heipark
  • 浏览: 2077015 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

读取jar内资源文件

    博客分类:
  • Java
 
阅读更多

    因为项目需要将配置文件打包到jar包,然后再MR job中读取资源。

    我以读取"hadoop-core-0.20.2-cdh3u2.jar"中core-default.xml配置文件举例,代码如下:

 

	public static void main(String[] args) throws InterruptedException, FileNotFoundException, IOException {
		InputStream in = FileSystem.class.getClass().getResourceAsStream("/core-default.xml");
		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		String s= "";
		while((s= reader.readLine()) != null){
			System.out.println(s);
		}
	}

 我这里引用了FileSystem.class的路径,其实只要是在hadoop-core-0.20.2-cdh3u2.jar包中任何一个class都可以。

 

 

参考:http://www.iteye.com/topic/483115

 

 

-- heipark

 

 

分享到:
评论
1 楼 di1984HIT 2014-06-20  
不错,不错。

相关推荐

Global site tag (gtag.js) - Google Analytics