Commit b90e27e8 by fudahua

feat: 新版本的下载

parent 4da4c154
......@@ -9,6 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
public class HDFSUtil {
private static Logger logger = LoggerFactory.getLogger(HDFSUtil.class);
......@@ -32,8 +33,8 @@ public class HDFSUtil {
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS",hdfsUrl);
try {
fileSystem = FileSystem.get(configuration);
} catch (IOException e) {
fileSystem = FileSystem.get(new URI(hdfsUrl),configuration,"hadoop");
} catch (Exception e) {
logger.info("hdfs初始化失败-{}",e);
}
}
......
import com.gic.cloud.data.hook.service.HDFSUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
......@@ -6,14 +7,16 @@ import java.io.IOException;
public class hdfs {
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS","hdfs://10.0.1.13:4007");
try {
FileSystem fileSystem = FileSystem.get(configuration);
fileSystem.copyToLocalFile(false,new Path("/data/emr/order-1.csv"),new Path("D:\\testorder"));
fileSystem.close();
} catch (IOException e) {
e.printStackTrace();
}
// Configuration configuration = new Configuration();
// configuration.set("fs.defaultFS","hdfs://10.0.1.13:4007");
// try {
// FileSystem fileSystem = FileSystem.get(configuration);
// fileSystem.copyToLocalFile(false,new Path("/data/emr/order-1.csv"),new Path("D:\\testorder"));
// fileSystem.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
HDFSUtil.getInstance().downloadFile("/data/emr/order-1.csv","D:\\testorder");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment