整理一下hadoop中,Path,FileSystem,FSDataInputStream

源码中的解释

Path:

/** Names a file or directory in a {@link FileSystem}.
 * Path strings use slash as the directory separator.  A path string is
 * absolute if it begins with a slash.

*/

简单的就是包含文件的存储路径和一些其他信息的类,可以看下面的例子:

 
 
package testfs;

/**
 * Created by zhengbiubiu on 2018/5/9.
 */
public class Test1 {
    public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
        Configuration configuration = new Configuration();
        //常用获取文件系统的方式
//        FileSystem fis = path.getFileSystem(configuration);
//        FileSystem fis = FileSystem.get(configuration);
//        FileSystem.get(new URI(""), configuration, "");
//        FileSystem.get(new URI(""), configuration);
        //传文件的路径
        Path path = new Path(args[0]);
        //从路径可以获取相关的文件系统
        FileSystem fis = path.getFileSystem(configuration);
        //创建输入流-----输出流:[fis.create(path)]
        FSDataInputStream fsd = fis.open(path);
        PrintStream out = System.out;
        //查看相关信息
        System.out.println("Path------->" + path);
        System.out.println("filesystem---------->" + fis);
        System.out.println("FSDataInputStream------->" + fsd);
        //写出去
        IOUtils.copyBytes(fsd, System.out, 4096, false);
    }
}
 
 
看下输出的结果:

Path------->D:/MapReduce/hello.txt
filesystem---------->org.apache.hadoop.fs.LocalFileSystem@1b68b9a4
FSDataInputStream------->org.apache.hadoop.fs.ChecksumFileSystem$FSDataBoundedInputStream@4f9a3314
hello world

可以看出是本地的文件系统,包含的具体内容可以进源码看看。

下一篇看看FileSplit中包含哪些信息。






  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值