zoukankan      html  css  js  c++  java
  • 提供个HDFS的目录的路径,对该目录进行创建和删除操作。创建目录时,如果目录 文件所在目录不存在则自动创建相应目录;删除目录时,由用户指定当该目录不为空时是否还删 除该目录

    import java.io.IOException;
    import java.util.Scanner;
    import org.apache.hadoop.fs.*;
    
    
    
    public class G_CreateAndDelAlterVersion {
        public static void CreateFile(FSDataOutputStream out,FileSystem fs,Path p_remotepath)
        {
            try{
                out = fs.create(p_remotepath);
                System.out.println("create successfully");
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        public static void DelFile(FileSystem fs,Path p_remotepath)
        {
            try{
                if(fs.delete(p_remotepath, true))
                {
                    System.out.println("del successfully");
                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        public static void main(String arg[])
        {
            try{
                Var_init var = new Var_init();
                
                if(!var.fs.exists(var.p_remoteFilePath))
                    CreateFile(var.out,var.fs,var.p_remoteFilePath);
                else
                {
                    RemoteIterator<LocatedFileStatus> remoteIterator = var.fs.listFiles(var.p_remoteFilePath, true);
                    if(remoteIterator.hasNext())
                    {
                        System.out.println("File is not empty , are u sure u want to delete it? y/n");
                        Scanner sc = new Scanner(System.in);
                        String str = sc.next();
                        if(str.equals("y"))
                        {
                            DelFile(var.fs,var.p_remoteFilePath);
                        }
                        else if(str.equals("n"))
                        {
                            System.out.println("Cancle");
                        }
                        else
                        {
                            System.out.println("plz input right common");
                        }
                    }
                    
                }
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
    
    }
    View Code

    Var_init类参考 https://www.cnblogs.com/MiraculousB/p/13848744.html

  • 相关阅读:
    Java AbstractQueuedSynchronizer(AQS)
    CentOS Install Rancher & K3s
    CentOS Install Rancher & Kubernetes
    CentOS Install Kubernetes & Kubesphere
    支付宝小程序入门
    uni-app 抽奖
    APP上架
    uniapp微信小程序语音识别实现
    uniapp 安卓打包之导入的项目打包指导
    uniapp 支付宝 支付后不成功回调
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13848845.html
Copyright © 2011-2022 走看看