天天看點

Java 讀取Hadoop檔案系統檔案

放一個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());

}

Java 讀取Hadoop檔案系統檔案

最新内容請見作者的github頁:http://qaseven.github.io/