hadoop 文件系统API操作

配置参数:-DHADOOP_USER_NAME=hadoop

public class HdfsUtils {

	private static FileSystem fileSystem;

	@Before
public void init() throws IOException {
Configuration conf = new Configuration();
// fileSystem = FileSystem.get(conf);
} @Test
public void download() throws IOException {
Configuration conf = new Configuration();
FileSystem fileSystem = FileSystem.get(conf);
Path path = new Path("/test");
FSDataInputStream inStream = fileSystem.open(path);
OutputStream outStream = new FileOutputStream("D:/test.txt");
IOUtils.copy(inStream, outStream);
} @Test
public void upload2() throws IllegalArgumentException, IOException {
fileSystem.copyFromLocalFile(new Path("D:/test.txt"), new Path("/test.txt"));
}

  

上一篇:PHP/ThinkPHP5 框架集成微博登录入库流程示意


下一篇:docker、oci、runc以及kubernetes梳理