zoukankan      html  css  js  c++  java
  • hdfs的java接口简单示例

    public class HDFSDemo {
        
        private FileSystem fs = null;
        @Before
        public void init() throws IOException, URISyntaxException, InterruptedException{
            fs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration());
        }
        @Test
        //递归删除文件或者文件夹
        public void  testDel() throws IllegalArgumentException, IOException{
            boolean flag = fs.delete(new Path("/test"),true);
            System.out.println(flag);
        }
        @Test
        //创建目录
        public void testMkdir() throws IllegalArgumentException, IOException{
            boolean flag = fs.mkdirs(new Path("/Google3Papers"));
            System.out.println(flag);
        }
        @Test
        //上传文件
        public void testUpload() throws IllegalArgumentException, IOException{
            FSDataOutputStream out = fs.create(new Path("/Google3Papers/Google-Bigtable1.0.pdf"));
            FileInputStream in = new FileInputStream(new File("/Users/fengmingyue/Desktop/Google-Bigtable1.0.pdf"));
            IOUtils.copyBytes(in, out, 2048, true);
        }
        @Test
        //下载文件
        public void testDownload() throws IllegalArgumentException, IOException{
            InputStream in = fs.open(new Path("/test"));
            FileOutputStream out = new FileOutputStream(new File("/Users/fengmingyue/Desktop/ttt"));
            IOUtils.copyBytes(in, out, 2048, true);
        }
    }
  • 相关阅读:
    用栈消除递归调用,实现DFS【伪代码】
    B树残缺版
    lvm
    RAID独立冗余磁盘阵列
    压缩、归档
    磁盘、文件系统
    setfacl、getfacl
    locate,find
    vim编辑器
    sed流编辑器
  • 原文地址:https://www.cnblogs.com/fengmingyue/p/6347578.html
Copyright © 2011-2022 走看看