hadoop第一个例子
Posted 棍子哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hadoop第一个例子相关的知识,希望对你有一定的参考价值。
Java.io.URL
1、编写java程序
package com.company; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import org.apache.hadoop.fs.FsUrlStreamHandlerFactory; import org.apache.hadoop.io.IOUtils; public class Main { static { URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory()); } public static void main(String[] args) throws MalformedURLException,IOException { InputStream in=null; try{ in = new URL(args[0]).openStream(); IOUtils.copyBytes(in,System.out,4096,false); }finally { IOUtils.closeStream(in); } } }
2、打包为javaWrkspace.jar
3、[email protected]:~/software/hadoop$
bin/hadoop jar /home/simon/javaWrkspace/out/artifacts/javaWrkspace_jar/javaWrkspace.jar hdfs://localhost:9000/test/hello
org.apache.hadoop.fs.FileSystem
1、
import java.io.IOException; import java.io.InputStream; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; public class hdfsclient { public static void main(String[] args) throws IOException{ String uri="hdfs://localhost:9000/test/hello"; Configuration conf=new Configuration(); FileSystem fs = FileSystem.get(URI.create(uri),conf); InputStream in=null; try{ in = fs.open(new Path(uri)); IOUtils.copyBytes(in,System.out,4096,false); }finally { IOUtils.closeStream(in); } } }
2、打包为javaWrkspace.jar
3、[email protected]:~/software/hadoop$
bin/hadoop jar /home/simon/javaWrkspace/out/artifacts/javaWrkspace_jar2/javaWrkspace.jar hdfsclient
以上是关于hadoop第一个例子的主要内容,如果未能解决你的问题,请参考以下文章
hadoop第一个UDF小例子 此博文包含图片(2013-09-23 19:19:13)