• 7月26日


    查看了很多资料之后,我成功解决maven报错,

    需要在VM  这个地方输入证书相关数据-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true  这一行十分关键,这样才能下载

    副本的个数这个参数的设置是有优先级的,

    从右到左优先级一路下降

    编写hdfs 的API

    //判断是文件还是文件夹
    @Test
    public void testFile() throws IOException {
        FileStatus[] listStatus = fs.listStatus(new Path("/"));
        for (FileStatus status : listStatus) {
            if (status.isFile()) {
                System.out.println("文件:"+status.getPath().getName());
            }else{
                System.out.println("目录:"+status.getPath().getName());
            }
        }
    }

    //获取文件详细信息
    @Test
    public void fileDetail() throws IOException {
        //第二个参数是否递归
       
    //获取全部文件,返回一个迭代器
       
    RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);
        //遍历文件
       
    while(listFiles.hasNext()){
            LocatedFileStatus fileStatus =listFiles.next();
            System.out.println("===="+fileStatus.getPath()+"======");
            System.out.println("===="+fileStatus.getPermission()+"====");
            System.out.println(fileStatus.getOwner());
            System.out.println(fileStatus.getGroup());
            System.out.println(fileStatus.getLen());
            System.out.println(fileStatus.getModificationTime());
            System.out.println(fileStatus.getReplication());
            System.out.println(fileStatus.getBlockSize());
            System.out.println(fileStatus.getPath().getName());

            //获取块信息
           
    BlockLocation[] blockLocations = fileStatus.getBlockLocations();
            System.out.println(Arrays.toString(blockLocations));
        }
    }
    //文件更名和移动
    @Test
    public void testmv() throws IOException {
        //参数:1 原文件路径 2 目标文件路径
       
    //对文件名的修改
       
    fs.rename(new Path("/xiyou/huaguoshan/hgg.txt"),new Path("/xiyou/huaguoshan/haogegeg.txt"));
        //文件的移动和改名
      
    // fs.rename(new Path("/xiyou/huaguoshan/hgg.txt"),new Path("/sanguo/haogegeg.txt"));
        //
    目录更名
       
    fs.rename(new Path("/xiyou"),new Path("/shiezhuan"));
    }
    //删除
    @Test
    public void testRm() throws IOException {
        //参数  参数1:原文件路径  参数2:是否递归删除
       
    //删除文件
       
    fs.delete(new Path("/社会.docx"),false);
        //删除空目录
       
    fs.delete(new Path("/xiyou"),false);
        //删除非空目录   !!!!!是有区别的
       
    fs.delete(new Path("/sanguo"),true);
    }
    public void init() throws URISyntaxException, IOException, InterruptedException {
        //连接集群namenode地址
       
    URI uri = new URI("hdfs://hadoop102:8020");
        //创建一个配置文件
       
    Configuration configuration = new Configuration();
        //用户
       
    String user ="jxp";
        //获取到了客户端对象
       
    fs = FileSystem.get(uri,configuration,user);//ctrl alt f  将变量抽取成私有变量
    }
    @After
    public void colse() throws IOException {
        //关闭资源
       
    fs.close();
    }
    @Test
    public void testmkdir() throws URISyntaxException, IOException, InterruptedException {
        //创建一个文件夹
       
    fs.mkdirs(new Path("/xiyou/huaguoshan"));

    }
    //上传
    @Test
    public void testPut() throws IOException {
        //参数:参数一:原数据是否删除 参数二:是否允许覆盖  参数三:源数据路径 参数四:目的地路径
       
    fs.copyFromLocalFile(false,true,new Path("E:\maven\hgg.txt"),new Path("/xiyou/huaguoshan"));
    }

    //下载
    @Test
    public void testGet() throws IOException {
        //参数: 参数一:原文件是否删除  参数二:源文件路径HDFS 参数三 :目标地址路径
       
    fs.copyToLocalFile(false,new Path("hdfs://hadoop102/xiyou/huaguoshan"),new Path("E:\maven"),true);
    }

    今天的学习时间:12:43 到18:04

  • 相关阅读:
    在Windows10上安装Linux子系统
    《ln--软连接》--linux命令
    【转】最详细的Log4J使用教程
    7 str字符串的内置函数
    6.1 range创建数值序列
    6 int数值类型的内置函数
    linux shell 字符串操作(长度,查找,截取,替换)详解
    awk 字符串处理函数
    Shell字符串截取
    5 python基本数据类型
  • 原文地址:https://www.cnblogs.com/buyaoya-pingdao/p/15062893.html
Copyright © 2020-2023  润新知