HDFS特点 HDFS优点 支持处理超大文件 可运行在廉价机器上 高容错性 流式文件写入 HDFS缺点 不适合低延时数据访问场景 不适合小文件存取场景 不适合并发写入,文件随机修改场景
-------创建一个文件夹
public void testMKdir() throws URISyntaxException, IOException, InterruptedException { //1.创建配置 Configuration conf=new Configuration(); //2.获取文件系统 FileSystem fs=FileSystem.get(new URI("hdfs://192.168.137.111:9000"),conf,"root"); //3.调用API操作 fs.mkdirs(new Path("/hdfs")); //4.关闭资源 fs.close(); }上传:
public void testCopyFromLocalFile() throws URISyntaxException, IOException, InterruptedException { Configuration conf=new Configuration(); FileSystem fs=FileSystem.get(new URI("hdfs://192.168.137.111:9000"),conf,"root"); fs.copyFromLocalFile(new Path("D://aaa.txt"),new Path("/hdfs/mmm.txt")); fs.close(); }可通过hdfs界面查看
下载:
public void testCopyFromLocalFile() throws URISyntaxException, IOException, InterruptedException { Configuration conf=new Configuration(); FileSystem fs=FileSystem.get(new URI("hdfs://192.168.137.111:9000"),conf,"root"); fs.copyFromLocalFile(new Path("D://aaa.txt"),new Path("/hdfs/mmm.txt")); fs.close(); }---------删除
public void testDelete() throws IOException, URISyntaxException, InterruptedException { Configuration conf=new Configuration(); FileSystem fs=FileSystem.get(new URI("hdfs://192.168.137.111:9000"),conf,"root"); fs.delete(new Path("/hdfs"),true); fs.close(); }