package com.cn.demo01;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.junit.Test;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
public class HdfsOperate {
//通过URL来获取,不常用了解
@Test
public void downHdfsFiles() throws IOException {
//注册一个驱动,访问hdfs文件系统
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
String url = "hdfs://node01:8020/profile";
InputStream inputStream = new URL(url).openStream();
OutputStream outputStream = new FileOutputStream(new File("D:\\hello.txt"));
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
}
//通过FileSystem类来获取,了解源