• 提供个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

  • 相关阅读:
    SoapUI 使用笔记
    git 使用笔记(二)
    git 使用笔记(一)
    jquery 拓展
    hdu 1024 Max Sum Plus Plus (DP)
    hdu 2602 Bone Collector (01背包)
    hdu 1688 Sightseeing (最短路径)
    hdu 3191 How Many Paths Are There (次短路径数)
    hdu 2722 Here We Go(relians) Again (最短路径)
    hdu 1596 find the safest road (最短路径)
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13848845.html
Copyright © 2020-2023  润新知