放一个hello的文件到hadoop 文件系统 根目录:
[root@hadoop local]# touch hello
[root@hadoop local]# vi hello
[root@hadoop local]# hadoop fs -put hello /
代码:
package hadoop.jack.javacallhadoop;
import java.net.url;
import org.apache.hadoop.conf.configuration;
import org.apache.hadoop.fs.fsurlstreamhandlerfactory;
import org.apache.hadoop.io.ioutils;
public class app1 {
public static string hdfs_path="hdfs://hadoop:9000/hello";
/**
* @param args
*/
public static void main(string[] args) throws exception{
url.seturlstreamhandlerfactory(new fsurlstreamhandlerfactory());
final url url =new url(hdfs_path);
inputstream in = url.openstream();
ioutils.copybytes(in, system.out, new configuration());
}
最新内容请见作者的github页:http://qaseven.github.io/