760176104 发表于 2016-12-5 10:23:45

运行Hadoop权威指南中的例子:3.5.2:FileSystemCat

  1、编写代码:

package crt.hadoop.test;
import java.io.InputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class FileSystemCat {
public static void main(String[] args) throws Exception{
String uri = args;
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
InputStream in = null;
try{
in = fs.open(new Path(uri));
IOUtils.copyBytes(in, System.out, 4096, false);
} finally{
IOUtils.closeStream(in);
}
}
}
  2、把FileSystemCat.java复制到$HADOOP_HOME/build/classes/crt/hadoop/test
  3、编译:
  $ javac  -classpath  $HADOOP_HOME/hadoop-common-0.21.0.jar 
  $HADOOP_HOME/build/classes/crt/hadoop/test/FileSystemCat.java
  4、运行:
  $ export  HADOOP_CLASSPATH=build/classes
  $ hadoop  crt.hadoop.test.FileSystemCat  hdfs://hadoop-namenode:9001/tmp/readdatatest.txt
  运行结果:
  hello hadoop
页: [1]
查看完整版本: 运行Hadoop权威指南中的例子:3.5.2:FileSystemCat