文件下载
@Test
public void testCopyToLocalFile() throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), conf, "root");
fs.copyToLocalFile(new Path("/demo/test/readme-3.md"),new Path("/Users/ylj/demo/readme-3.md"));
fs.copyToLocalFile(true,new Path("/demo/test/readme-3.md"),new Path("/Users/ylj/demo/readme-3.md"));
fs.copyToLocalFile(true,new Path("/demo/test/readme-3.md"),new Path("/Users/ylj/demo/readme-3.md"),false);
fs.close();
System.out.println("~ok~");
}
文件删除
@Test
public void testDelete() throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), conf, "root");
fs.delete(new Path("/demo/test/readme.md"),true);
fs.close();
System.out.println("~ok~");
}
文件名更改
@Test
public void testRename() throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), conf, "root");
fs.rename(new Path("/demo/test/readme.md"),new Path("/demo/test/readme_bak.md"));
fs.close();
System.out.println("~ok~");
}