用 java.net.URL 输出HDFS中指定文件的文本到终端

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;
import java.io.InputStream;
import java.net.URL;

/**
 * 用 java.net.URL 和 org.apache.hadoop.fs.FsURLStreamHandlerFactory 编程
 * 完成 输出HDFS中指定文件的文本到终端中
 */
public class UrlInputStreamHandlerFactory {

    public static void main(String[] args) throws Exception {
        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
        URL url = new URL("hdfs://hadoop102:8020/in/hello.txt");
        InputStream inputStream = url.openStream();
        IOUtils.copyBytes(inputStream, System.out, new Configuration());
    }
}

你可能感兴趣的:(hadoop,hdfs)