环境:Hadoo
例:直接使用FileSystem以标准输出格式显示Hadoop文件系统中的文件
编写JAVA文件
import org.a; import org.a; import org.a; import org.a; import java.io.InputStream; import java.net.URI; public class FileSystemCat { public static void main(String[] args) throws Exception { String uri = args[0]; Configuration conf = new Configuration(); FileSystem fs = FileSy(uri), conf); InputStream in = null; try { in = (new Path(uri)); IOU(in, Sy, 4096, false); } finally { IOU(in); } } }设置JAVA_HOME环境变量,将$JAVA_HOME/bin添加到PATH环境变量
设置Hadoop的类目录( HADOOP_CLASSPATH)
[grid@hadoop1 ]# vi con # The java implementation to use. Required. export JAVA_HOME=/usr/java # Extra Java CLASSPATH elements. Optional. export HADOOP_CLASSPATH=/home/grid//myclasses上传编辑好的JAVA文件
[grid@hadoop1 ]$ mkdir myclasses [grid@hadoop1 ]$ cd myclasses [grid@hadoop1 myclasses]$ rz编译java文件
[grid@hadoop1 myclasses]$ javac -classpath .. FileSy执行:
[grid@hadoop1 ]$ ./bin/hadoop FileSystemCat hdfs://hadoop1:9000/user/grid/in Hello Hadoop Java API