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);
        }
    }
  • 相关阅读:
    Elementui:选择框
    Cesium之Cesium3DTileStyle
    Cesium粒子系统:雨雪云效果
    Cesium之3dtiles模型选择问题
    3dtiles贴地
    Android ListView异步加载图片
    Android的硬件加速
    Android ANR
    每天一点Linux 查看Ubuntu的版本号
    Android log system
  • 原文地址:https://www.cnblogs.com/fengmingyue/p/6347578.html
Copyright © 2011-2022 走看看