本地javaAPI操作打开HDFS文件
@Test
public void makbir(){
Configuration configuration = new Configuration();
//configuration.set("dfs.replication","1");
try{
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.0.105:9000"),
configuration,"root");
//打开HDFS文件
FSDataInputStream in = fs.open(new Path("/a1"));
IOUtils.copyBytes(in,System.out,1024);
fs.close();
}catch (IOException e){
e.printStackTrace();
}catch (InterruptedException e){
e.printStackTrace();
}catch (URISyntaxException e){
e.printStackTrace();
}
}
/**
* 测试文件名更改
* @throws Exception
*/
@Test
public void rename() throws Exception {
Path oldPath = new Path("/b.txt");
Path newPath = new Path("/c.txt");