java通过调用HDFS系统的FileSystem等API 直接读取HDFS的压缩文件会产生乱码

解决方法:

1.调用解码的API,解码后通过IO流处理。

public static void main(String[] args) throws IOException {     
     Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
boolean tag=fs.exists(new Path(args[0]));
String ftag=tag?"exist":"not exist";
logger.info("===>the HDFS File :"+ args[0] +"is "+ftag);
InputStream in=fs.open(new Path(args[0]));     //核心转换部分
CompressionCodecFactory factory = new CompressionCodecFactory(conf);
CompressionCodec codec = factory.getCodec(new Path(args[0]));
CompressionInputStream compin=codec.createInputStream(in);
BufferedReader br= new BufferedReader(new
InputStreamReader(compin)); String line="";
while((line=br.readLine())!=null){
//TODO
}
//TODO 关闭流
}

2.文件不大的话,也可以hadoop fs -get xxxx,下载到本地解压后当成普通文件处理。

推荐使用第一种。

other

多个MR顺序执行时,中间如果结果较大几百G,可已使用

FileOutputFormat.setCompressOutput(job1, true);
FileOutputFormat.setOutputCompressorClass(job1, GzipCodec.class);

压缩比很高,可提高效率

最新文章

  1. iOS UITextField的returnkey点击事件
  2. web页面隐藏鼠标
  3. Linux重定向相关(转载帖,供自己cookbook)
  4. Java:String、StringBuffer和StringBuilder的区别
  5. C#中string类型前加@标志的作用
  6. Linux makefile教程之概述一[转]
  7. 用原生js模仿jquery
  8. Namespace declaration statement has to be the very first
  9. [TPYBoard-Micropython之会python就能做硬件 7] 学习使用蓝牙模块及舵机
  10. 201521123084 《Java程序设计》第6周学习总结
  11. Python之路,进程、线程、协程篇
  12. uva11916 Emoogle Grid (BSGS)
  13. Android事件总线(三)otto用法全解析
  14. HttpServletResponse和HttpServletRequest
  15. ORA-16038: log 3 sequence# 103 cannot be archived
  16. python 形参
  17. 兼容性测试中如何切换和管理多个JDK版本
  18. 关于 img 父容器比img图片要多4个像素的问题
  19. python中动态导入模块
  20. 【BZOJ3232】圈地游戏 分数规划+最小割

热门文章

  1. base62与long的相互转换
  2. hyper-v安装centos后配置网络
  3. kafka压测
  4. HTML+css基础 三大列表
  5. tensorflow 梯度裁剪
  6. Java中接口和Sala中的特质的区别?
  7. Python 3 的 int 类型详解(为什么 int 不存在溢出问题?)
  8. ASP.NET Core 应用程序状态
  9. CentOS 7.0 使用yum 安装 Mariadb
  10. rabbitMq 学习笔记(一)