Hadoop 读取文件API报错
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报错的更多相关文章
- 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:
使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...
- python利用xlrd读取excel文件始终报错原因
1.代码按照网上百度的格式进行书写如下: 但运行后,始终报错如下: 百度了xlrd网页: 分明支持xls和xlsx两种格式的文件,但运行始终报错. 最后找到原因是因为我所读取的文件虽然是以.xls命名 ...
- 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 ...
- python 读取配置文件总是报错 configparser.NoSectionError: No section:
本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...
- 记一次用python 的ConfigParser读取配置文件编码报错
记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...
- 【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.原因,工作队列被占用,只需 ...
- 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工程图片资源命名的问 ...
- 在PHP5.4上使用Google翻译的API报错
/********************************************************************** * 在PHP5.4上使用Google翻译的API报错 * ...
- 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 ...
随机推荐
- SQL Server临时表
[]SQL Server临时表]()https://docs.microsoft.com/zh-cn/sql/relational-databases/tables/temporal-tables)
- Nutch的安装和配置
Nutch是一个Java实现的网络爬虫.Nutch的安装可以使用二进制包,也可以使用源代码安装.这里介绍用二进制包安装. 1. 下载apache-nutch-1.12-bin.tar.gz,并且解压, ...
- SQL Server事务复制搭建与同步经验
0. 环境 无域环境 发布服务和分发服务器同一台主机 角色 主机名 IP 发布名 发布库名/订阅库名 发布服务器 Server1 192.168.1.100 test3 db1 分发服务器(与发布服务 ...
- 使用Bootstrap+metisMenu完成简单的后台管理界面
零. 写在前面 作者最近在一个小项目中需要写后台管理界面,在互联网上绕了一圈,最后决定使用Bootstrap+metisMenu来完成.理由1:Bootstrap是目前流行的前端框架,风格简约,简单易 ...
- code vs 2597 团伙
题目描述 Description 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么他们要么是朋友,要么是敌人.而且有一点是肯定的,就是: 我朋友的朋友是我的朋友: 我敌人的敌人也是我的朋友 ...
- Fix: Windows Script Host access is disabled on this machine
If you receive this Windows Script Host access is disabled on this machine, Contact your administrat ...
- windows DLL中使用COM的注意事项
windows的DLL开发是有需要注意的地方的,不然会造成一些问题.由于我最近的使用不当,又造成了问题,虽然之前有写过一篇笔记, http://www.cnblogs.com/foohack/p/66 ...
- MATLAB R2018a 输入中文却显示方框问号的问题
[问题] 安装完成软件后,我把编辑区字体重设为 consolas : 就会出现 输入中文注释却没办法正常显示的问题: [解决办法] 把字体改成 Monospaced (查了一下 说是MATLAB默认字 ...
- SoapUI利用Groovy把外部数据加载到request中
默认已经用Groovy把外部数据给读取出来了,关键是读取出来后,如何加载到request中去?这里提供了两种方法:1.该Groovy脚本的名称是"setUp" def num = ...
- 【Visual Studio】Visual C# 中XML注释的使用(含注释在开发时显示换行)
为函数方法注释说明要用到 xml 语句 <summary> 段落说明 </summary> .<para> 新段示例说明 </para>.<par ...