首页 > 大数据 > Hadoop > hadoop实验1 URLCat
hadoop权威指南3.1 实验
JAVA代码
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;
import java.io.InputStream;
import java.net.URL;
public class URLCat {
static {
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
}
public static void main(String[] args) throws Exception {
InputStream in = null;
try {
in = new URL(args[0]).openStream();
IOUtils.copyBytes(in, System.out, 4096, false);
} finally {
IOUtils.closeStream(in);
}
}
}
编译javac -classpath ../hadoop-core-1.1.2.jar URLCat.java
必须指定 classpath
运行
hadoop URLCat hdfs://hadoop1:9000/user/hadoop/in/test1.txt
开始一直报错,检查很多次没发现问题,原因就是hdfs后的 ":"写成了":",即是中文的
[hadoop@hadoop1 myclass]$ hadoop URLCat hdfs://localhost:9000/user/hadoop/in/test1.txt
Exception in thread "main" java.net.MalformedURLException: no protocol: hdfs://localhost:9000/user/hadoop/in/test1.txt
at java.net.URL.
at java.net.URL.
at java.net.URL.
at URLCat.main(URLCat.java:12)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/582521/viewspace-1455452/ ,如需转载,请注明出处,否则将追究法律责任。