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 ...
随机推荐
- Spark分布式集群的搭建和运行
集群共三台CentOS虚拟机,一个Matser,主机名为master:三个Worker,主机名分别为master.slave03.slave04.前提是Hadoop和Zookeeper已经安装并且开始 ...
- MySql8.0数据库链接报错The driver has not received any packets from the server
1.我使用MySql数据库8.0版本,然后驱动改成了 jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306 ...
- vue css 模块化编程 CSS Modules Scoped
1.scoped https://vue-loader.vuejs.org/zh/guide/scoped-css.html 2.module https://vue-loader.vuejs.org ...
- OpenCV学习代码记录——canny边缘检测
很久之前学习过一段时间的OpenCV,当时没有做什么笔记,但是代码都还在,这里把它贴出来做个记录. 代码放在码云上,地址在这里https://gitee.com/solym/OpenCVTest/tr ...
- 如何使用 MSBuild.exe 生成解决方案中的特定目标
以前都是直接使用VS或者msbuild生成整个解决方案,或者只构建单个工程. 这回使用msbuild构建单个工程的时候出现了问题,因为工程中使用了SolutionDir这个宏来定位第三方库路径. 对于 ...
- Docker修改默认存储位置(转)
方法一.软链接 默认情况下Docker的存放位置为:/var/lib/docker 可以通过下面命令查看具体位置: sudo docker info | grep "Docker Root ...
- NE555
Turn-off time less than 2μsMax. operating frequency greater than 500kHzTemperature stability of 0.00 ...
- Linux桌面“彩”起来:桌面环境及窗口管理器大盘点
2011-02-22 11:49:50 看到这个标题,很多人一定认为桌面环境和窗口管理器是一回事,但严格来说窗口管理器和桌面环境是有区别的.桌面环境(Desktop Environments)是最 ...
- 简述MVC
强调:mvc不是框架而是一种设计模式 分层结构的好处:1.降低了代码之间的耦合性 2.提高了代码的重用性 一. 概述 MVC的全名Model View Controller,即模型-视图-控制器的缩写 ...
- ant执行jar包中的main方法
<project name= "myproject" basedir= "." default="main"> <p ...