Putmerge的各种报错

Putmerge程序的主要工作内容为:将本地文件合并到hdfs上的某一个文件中。

看似简单的问题,结果bug多多。

public class Putmerge {
	
	public static void main(String[] args) {
		Configuration conf = new Configuration();
		try {
			FileSystem hdfs = FileSystem.get(URI.create("hdfs://carweb94/"),conf);
			conf.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem");
			LocalFileSystem local = FileSystem.getLocal(conf);
			//设定输入目录和输出目录
			Path inputDir = new Path(args[0]);
			Path hdfsFile = new Path(args[1]);
			FSDataOutputStream out = hdfs.create(hdfsFile);
			//得到本地文件列表
			FileStatus[] inputFiles = local.listStatus(inputDir);
			for (int i = 0; i < inputFiles.length; i++) {
				FSDataInputStream in = local.open(inputFiles[i].getPath());
				int readIndex = 0;
				byte[] buffer = new byte[1024];
				while((readIndex = in.read(buffer)) > 0) {
					out.write(buffer, 0, readIndex);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

1. hdfs java.io.IOException: Mkdirs failed to create

这个问题的出现原因大致是:FileSystem.get(conf);这句实则连接的是本地文件file:///所以bug多多,

下面是某位同学辛苦总结的,并附上解决办法:修改程序: FileSystem hdfs = FileSystem.get(URI.create("hdfs://localhost:9000/"), conf); 

http://blog.csdn.net/walkerjong/article/details/37763777


2.接下来你可能会抛这样的错:

Exception in thread "main" java.io.IOException: No FileSystem for scheme: file
这个得解决办法就是添加这句:conf.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem");

这个方法的来源及解释在这里:http://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file

3.第三个错也许就此也上场了:

xception in thread "main" java.io.IOException: No FileSystem for scheme: hdfs
解决办法是加jar包: hadoop-common,hadoop-hdfs,一个都不能少,听他的,没错!

来源请参考:http://heipark.iteye.com/blog/1997672

4.也许你的程序还会抛:

java.io.FileNotFoundException: XXXX (Is a directory)

很显然,这个程序没有排除子目录,请你本地的路径,也就是args【0】传一个目录,这个目录里只有文件,不能有子目录。

5.也许你的程序,她妹的还会抛错:例如

failed on connection exception: java.net.ConnectException: Connection refused

恭喜你,终于快要看到海岸了。。。这个错就是你连hdfs都没连上啊,哈哈哈,还做嘛呢。。。赶紧的,看看你的hdfs到底该写个啥才能连上吧。


出处:http://write.blog.csdn.net/postedit?ref=toolbar


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值