Exception in thread "main" org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block: BP-1124468226-10.0.2.15-1429879726015:blk_1073742186_1370 file=/user/testdir/yarn-site.xml
    at org.apache.hadoop.hdfs.DFSInputStream.chooseDataNode(DFSInputStream.java:889)
    at org.apache.hadoop.hdfs.DFSInputStream.fetchBlockByteRange(DFSInputStream.java:998)
    at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:1333)
    at org.apache.hadoop.fs.FSInputStream.readFully(FSInputStream.java:78)
    at org.apache.hadoop.fs.FSDataInputStream.readFully(FSDataInputStream.java:116)
    at com.hdfs.file.ReadFile.main(ReadFile.java:24)、

代码如下,在windows机器上运行,报上面的错误:

package com.hdfs.file;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; public class ReadFile { /**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Configuration conf=new Configuration();
FileSystem fs=FileSystem.get(conf);
Path path=new Path("hdfs://sandbox.hortonworks.com:8020/user/testdir/yarn-site.xml");
if(fs.exists(path)){
FSDataInputStream fsIn=fs.open(path);
FileStatus status=fs.getFileStatus(path);
byte[] buffer=new byte[Integer.parseInt(String.valueOf(status.getLen()))];
fsIn.readFully(0,buffer);
fsIn.close();
fs.close();
System.out.println("读取完成!");
System.out.println(new String(buffer));
}else{
throw new Exception("the file is not found!");
}
} }

将代码打成Jar包,放到hadoop集群上去运行,一切正常:

Hadoop 读取文件API报错的更多相关文章

  1. 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:

     使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...

  2. python利用xlrd读取excel文件始终报错原因

    1.代码按照网上百度的格式进行书写如下: 但运行后,始终报错如下: 百度了xlrd网页: 分明支持xls和xlsx两种格式的文件,但运行始终报错. 最后找到原因是因为我所读取的文件虽然是以.xls命名 ...

  3. Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence

    Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal mul ...

  4. python 读取配置文件总是报错 configparser.NoSectionError: No section:

    本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...

  5. 记一次用python 的ConfigParser读取配置文件编码报错

    记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...

  6. 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted

    1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...

  7. R.java 文件内报错:Underscores can only be used with source level 1.7 or greater。

    R.java 文件内报错:Underscores can only be used with source level 1.7 or greater 网上查找后得知是Android工程图片资源命名的问 ...

  8. 在PHP5.4上使用Google翻译的API报错

    /********************************************************************** * 在PHP5.4上使用Google翻译的API报错 * ...

  9. python2.7运行selenium webdriver api报错Unable to find a matching set of capabilities

    在火狐浏览器33版本,python2.7运行selenium webdriver api报错:SessionNotCreatedException: Message: Unable to find a ...

随机推荐

  1. Hadoop: Add third-party libraries to MapReduce job

    来自:http://hadoopi.wordpress.com/2014/06/05/hadoop-add-third-party-libraries-to-mapreduce-job/ Anybod ...

  2. C++库研究笔记--用__attribute__((deprecated)) 管理过时代码

    用__attribute__((deprecated)) 管理过时代码.同一时候保留兼容的接口 Linux下: #define DEPR_AFTER __attribute__((deprecated ...

  3. 《跟孩子学Python》

    1:Python对象之间的赋值是内容赋值而不是引用赋值 a = ["aaa","bbb","ccc"] b = a print a prin ...

  4. Python学习笔记九:正则表达式

    一:正则表达式的符号与方法 常用符号: .:匹配任何一个字符,换行符除外(所以,多行字符串中的匹配要特殊处理,见下面实例) *:匹配前一个字符0次或多次 +:匹配前一个字符1次或多次 ?:匹配前一个字 ...

  5. [Android]通过alias映射所有Busybox命令

    # 把Busybox所有的命令通过alias映射出来(若此命令不存在时) # 这么做只是为了平时敲命令行时无须额外的打 busybox (感觉很麻烦的说) for applet in $(busybo ...

  6. Linux-配置虚拟IP

    Linux下配置网卡ip别名何谓ip别名?用windows的话说,就是为一个网卡配置多个ip.什么场合增加ip别名能派上用场?布网需要.多ip访问测试.特定软件对多ip的需要...and so on. ...

  7. HttpClient库设置超时

    HttpClient库API跟Lucene一样,每个版本的API都变化很大,这有点让人头疼.就好比创建一个HttpClient对象吧,每一个版本的都不一样. 3.X是正常的Java语法 HttpCli ...

  8. Lua初学

    Lua很火啊,而且跟C,c++可以无缝结合,表示很给力,算是我的第三门语言吧,哈哈! 在官网上下载了源码了,和windows版的,表示编译器也很给力,直接可以用SciTE就可以写代码了. a = 1; ...

  9. MYSQL 5.5.32的单机多实例部署

    Centos6.6安装并配置单机多实例的MYSQL数据库 本文介绍安装单机多实例的MYSQL数据库的环境如下: 系统平台环境:Centos6.6 Mysql软件包:Mysql-5.5.32.tar.g ...

  10. [think]关于个人发展值得记住的一些建议 听别人的话,即使你不想听 不要只做不想 成功不能被复制,但失败总在不停复制。看看别人是怎么倒下的,你可以更早地成功

    [think]关于个人发展值得记住的一些建议 偶然看到一篇采访周爱民的文章,里面的一些建议虽然朴实无华,却感觉很有道理,特此记录: 记者:对于程序员的技术发展和职业规划能否给大家一些建议呢?----- ...