在Hadoop中,将Path对象转换为字符串输出
来源:互联网 发布:office卸载软件mac 编辑:程序博客网 时间:2024/05/14 05:24
Path对象转换为字符串的方法如下:
先把Path对象转换为URI对象,然后转换为String对象。
如果对Path对象直接调用toString()方法,只会打印出Path对象的名字+@+hashcode()。
原因是Hadoop中,Path类的toString()没有对Object类中的toString()进行重载。而Hadoop中,URI对象的toString()重载了Object中的方法。因而只能间接得到String类型。
如下例子是从Hadoop中读取一个文件目录的列表:
public class ListStatus {public static String ls(String arg) throws Exception {String uri = arg;Configuration conf = new Configuration();FileSystem fs = FileSystem.get(URI.create(uri), conf);Path path = new Path(uri);FileStatus[] status = fs.listStatus(path);Path[] listedPaths = FileUtil.stat2Paths(status);InputStream in = null;StringBuffer buff = new StringBuffer();for (Path p : listedPaths) { buff.append(p.toUri().toString()); buff.append('\n');}return buff.toString();}}
0 0
- 在Hadoop中,将Path对象转换为字符串输出
- 将字符串转换为整数并输出
- 在win32程序中,将浮点数转换为字符串
- 将.Net对象转换为Json字符串
- JS 将JSON对象转换为字符串
- 将json对象转换为字符串
- 将JSON字符串转换为String对象
- 将对象转换为json字符串
- JS 将JSON对象转换为字符串
- js如何将字符串转换为对象
- js 将字符串转换为json对象
- javascript将对象转换为字符串
- 将字符串转换为json对象和将json对象转换为json字符串
- java中使用XStream实现将对象转为xml格式字符串或者将xml格式的字符串转换为对象
- java中JSON将数组对象转换成JSON字符串输出实例
- java中 将对象转换为json
- 18-将字符串转换为Calendar对象(字符串处理)
- 将字符串转换为16进制的字符串(常用在串口编程中)
- php 数组,常用函数
- BZOJ 2190: [SDOI2008]仪仗队
- HTTP协议详解
- 黑马程序员———网络编程
- 014JavaAPI文档
- 在Hadoop中,将Path对象转换为字符串输出
- arm-linux中断机制之一:中断产生至进入do_asm_IRQ分析
- Android UI开发: 横向ListView(HorizontalListView)及一个简单相册的完整实现
- 设计模式之(Template Method)模版方法模式
- 行政村vV大V型成v虚报V型成
- Single Round Match 573 Round 1 - Division I, Level Two SkiResorts
- HTTP协议 (二) 基本认证
- putty命令学习
- jbpm API的helloword实例