/** 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