设为首页 加入收藏

TOP

整理一下hadoop中,Path,FileSystem,FSDataInputStream
2019-04-18 00:39:49 】 浏览:77
Tags:整理 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中包含哪些信息。






】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇win10上传数据到hadoop,环境配置 下一篇hadoop JOB的性能优化实践

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目