java: 通过URL读取hadoop HDFS

package tju;

import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLStreamHandlerFactory;

public class ReadFile3 {
    public static void main(String[] args) throws Exception {
/*        URL url = new URL("http://www.baidu.com");
        InputStream inputStream = url.openStream();
        IOUtils.copyBytes(inputStream, System.out, 4096, true);*/

        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
        URL url = new URL("hdfs://xxx.xxx.xxx.xxx:9000/tju/userinfo.txt");

        InputStream inputStream = url.openStream();
        IOUtils.copyBytes(inputStream, System.out, 4096, true);
    }
}


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