HadoopのファイルシステムAPI操作

オリジナルリンク: http://www.cnblogs.com/heml/p/6039794.html

設定パラメータ:-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"));
	}		 

  

ます。https://www.cnblogs.com/heml/p/6039794.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_30363509/article/details/94795943