1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
final static String hdfsUrl = "hdfs://localhost:8020";
public void testLargeNumberFileUpload() throws URISyntaxException, IOException, InterruptedException {
long startTime = System.currentTimeMillis();
System.out.println(new DateTime(startTime));
var rootPath = "E:/Data/wuhan-polygon-tile";
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", hdfsUrl);
FileSystem fs = FileSystem.get(new URI(hdfsUrl), new Configuration(), "test");
FileUtil.walkFiles(new File(rootPath), file -> {
if (file.isFile()) {
String fileName = file.getName();
String filePath = file.getAbsolutePath();
String targetPath = file.getAbsolutePath().replace("E:\\", "").replace("\\", "/");
try {
fs.copyFromLocalFile(false, new Path(filePath), new Path(targetPath));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
long allTime = System.currentTimeMillis() - startTime;
System.out.println(new DateTime(allTime));
}
|