配置参数:-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"));
	}		 

  

相关文章:

  • 2022-02-09
  • 2021-10-12
  • 2021-08-23
  • 2021-05-26
猜你喜欢
  • 2021-10-14
  • 2021-12-29
  • 2021-07-29
  • 2021-10-02
  • 2021-12-31
  • 2021-09-24
相关资源
相似解决方案