hdfs查看命令_windows命令提示符窗口

hdfs查看命令_windows命令提示符窗口publicclassHdfsClient1{privateFileSystemfs;//初始化一个FileSystem@Beforepublicvoidinit()throwsURISyntaxException,IOException,InterruptedException{//1:获取文件系统URIuri=newURI(“hdfs://myhadoop105:9820”);.

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

public class HdfsClient1 {
    private FileSystem fs;
    //初始化一个FileSystem
    @Before
    public void init() throws URISyntaxException, IOException, InterruptedException {
        //1:获取文件系统
        URI uri = new URI("hdfs://myhadoop105:9820");
        Configuration conf = new Configuration();
        conf.set("dfs.replication","6");
        String user = "atguigu";
        fs = FileSystem.get(uri, conf, user);

    }
    @After
    public void closeResources() throws IOException {
        //3:关闭资源
        fs.close();
    }
    @Test
    public void testMkdir() throws IOException {
        fs.mkdirs(new Path("/hdfs/windowsOperator/operator01"));
    }
    @Test
    public void testPut() throws IOException {
        fs.copyFromLocalFile(false , false , new Path("G:/code/test/day08课堂记录.txt") , new Path("/hdfs/windowsOperator/operator01"));
    }
    @Test
    public void testGet() throws IOException {
        fs.copyToLocalFile(new Path("/hdfs/windowsOperator/operator01"),new Path("G:\\code\\test\\test"));
    }
    @Test
    public void testMove() throws IOException {
        fs.rename(new Path("/hdfs/windowsOperator/day08课堂记录.txt"),new Path("/hdfs/windowsOperator/day08"));
    }
    @Test
    public void testDelete() throws IOException {
        fs.delete(new Path("/hdfs/windowsOperator/operator01"),true);
    }

    @Test
    public void testIsFile() throws IOException {
        FileStatus[] fileStatuses = fs.listStatus(new Path("/"));
        for (FileStatus fileStatus : fileStatuses) {
            //判断是否是文件
            if (fileStatus.isFile()){
                System.out.println("-:"+fileStatus.getPath().getName());

            }else {
                System.out.println("d:" + fileStatus.getPath().getName());
            }

        }


    }

    @Test
    public void testListFiles() throws IOException {
        // f:要查看的目录路径
        // r:是否递归查看
        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.getBlockLocations());
            System.out.println(fileStatus.getPath().getName());

            //快信息
            BlockLocation[] blockLocations = fileStatus.getBlockLocations();
            System.out.println(Arrays.toString(blockLocations));

        }


    }


}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/186043.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python numpy数组切片_python列表切片详解

    python numpy数组切片_python列表切片详解python的数组切片操作很强大,但有些细节老是忘,故写一点东西记录下来。在python&numpy中切片(slice)对于一维数组来说,python的list和numpy的array切片操作都是相似的。无非记住arr[start:end:step]即可下面是几个特殊的例子[:]表示复制源列表负的index表示,从后往前。-1表示最后一个元素。相对于一维数组而言,二维(多维)数组用的会更多…

    2022年8月13日
    1
  • Sorting It All Out

    Sorting It All Out

    2021年9月1日
    55
  • Java HttpURLConnection setRequestProperty(“content-length“, “0“)不起作用

    Java HttpURLConnection setRequestProperty(“content-length“, “0“)不起作用Post验证Url合法的时候,今天突然遇到一个用IIS的客户,结果返回411的statuscode.搜索原因是请求头中没有设置Content-Lenght。网上的教程说用setRequestProperty(“content-length”,“0”)设置一下,结果我测试还是返回411.调试发现:为了安全,这些头默认是不允许指自定义的。可以通过下面方法打开,尽量将下面的语句放到main中:System.setProperty(“sun.net.http.allowRestrictedHead

    2022年9月3日
    6
  • plc的移位指令C语言实现,移位指令做流水灯-PLC中使用移位指令是如何实现移位动作的-电气资讯 – 电工屋…「建议收藏」

    plc的移位指令C语言实现,移位指令做流水灯-PLC中使用移位指令是如何实现移位动作的-电气资讯 – 电工屋…「建议收藏」移位指令的详述一般格式移位操作符(如SHR)OPR,CNT.其中OPR用除立即数外的任何寻址方式。移位次数由CNT决定,在8086中可以是1或CL,CNT为1时只移一位;如果需要移位的次数大于1时,需要先将移位次数存入CL寄存器中,而移位指令中的CNT写为CL即可。在其他机型中可使用CL和CNT,且CNT的值除可用1外,还可以用8位立即数指定范围从1到31的移位次数。有关OPR和CNT的规定…

    2022年6月5日
    30
  • 如何在docker容器中运行docker命令

    如何在docker容器中运行docker命令欢迎关注个人微信公众号:devopscube前言​Docker作为目前炙手可热的容器运行环境,越来越多的应用到应用的部署当中。这种一次打包,随处运行的模式备受好评,也节约了很多环境配置的麻烦。很多软件运行时都提供了docker的镜像部署方式,我们可以看到常用的组件,开源的项目,都会提供docker镜像,或者用于打包镜像的dockerfile。所以Docker已然成为了软件…

    2022年5月17日
    156
  • laravel 自定义分页样式「建议收藏」

    laravel 自定义分页样式「建议收藏」以laravel的默认表users表为例,插入100条数据$arr=[];for($i=0;$i<100;$i++){$arr[]=[‘name’=>’NAME_’.$i,’email’=>”email@{$i}.com”,’password’=>$i,’created_at’=>date(‘Y-m-dH:i:s’),’updated_…

    2022年7月17日
    13

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号