放一个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.io.InputStream;
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/