运行HDFS程序

step1

用elipse 建立一个新的工程,并命名为ListHDFS


step2

右键点击工程,Properties->Java Build Path->Libraries点击Add External JARs,选择在${HADOOP_HOME}上的.jar文件


step3

新建Class文件,并命名为ListAllFile.java


step4

输入文件

<pre name="code" class="java">import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;

public class ListAllFile {
	
	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		
		FileSystem fs = FileSystem.get(conf);
		
		Path[] paths = new Path[args.length];
		
		for (int i=0; i<paths.length; i++) {
			paths[i] = new Path(args[i]);
		}
		
		FileStatus[] status = fs.listStatus(paths);
		Path[] listedPaths = FileUtil.stat2Paths(status);
		
		for(Path p: listedPaths) {
			System.out.println(p);
		}		
	}

}



step5

确认没有错误后右键点击工程->export, 在Select and export destination: 下面输入JAR,选择JAR file,去掉.classpath 和 .project选项,并且输入JAR文件的输出路径


step6

在JAR的输出路径上键入 

hadoop jar ListAllFiles.jar ListAllFile /user/   (前提是hadoop的运行环境已经启动,并且hadoop已经添加进PATH环境变量)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值