• 删除HDFS中指定的文件。


     1 import java.text.SimpleDateFormat;
     2 import java.util.Scanner;
     3 
     4 import org.apache.hadoop.fs.FileStatus;
     5 import org.apache.hadoop.fs.FileSystem;
     6 import org.apache.hadoop.fs.LocatedFileStatus;
     7 import org.apache.hadoop.fs.Path;
     8 import org.apache.hadoop.fs.RemoteIterator;
     9 
    10 
    11 public class I_delFile {
    12     public static void ReadFilesStatus(FileStatus fileinfo)
    13     {
    14         SimpleDateFormat format = new SimpleDateFormat(
    15                 "yyyy-MM-dd HH:mm:ss");
    16         System.out.println("file path :"+fileinfo.getPath());
    17     }
    18     public static void DelFile(FileSystem fs,Path p_remotepath)
    19     {
    20         try{
    21             if(fs.delete(p_remotepath, true))
    22             {
    23                 System.out.println("del successfully");
    24             }
    25             else
    26             {
    27                 System.out.println("del fail");
    28             }
    29         }
    30         catch(Exception e)
    31         {
    32             e.printStackTrace();
    33         }
    34     }
    35     public static void main(String arg[])
    36     {
    37         try{
    38             Var_init var = new Var_init();
    39             String s_path = "/user";
    40             Path p_path = new Path(s_path);
    41             RemoteIterator<LocatedFileStatus> remoteIterator = var.fs.listFiles(p_path, true);
    42             while(remoteIterator.hasNext())
    43             {
    44                 var.fileinfo = remoteIterator.next();
    45                 ReadFilesStatus(var.fileinfo);
    46             }
    47             System.out.println("plz input the file u want to del like /user/hadoop/test");
    48             Scanner sc = new Scanner(System.in);
    49             String path = sc.next();
    50             Path remotepath = new Path(path);
    51             DelFile(var.fs,remotepath);
    52         }
    53         catch(Exception e){
    54             e.printStackTrace();
    55         }
    56     }
    57 }
    View Code

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

  • 相关阅读:
    视频播放的基本原理
    MPEG2 PS和TS流格式
    使用java连接hive,并执行hive语句详解
    杭电 3887 Counting Offspring
    java值传递
    android面试题之五
    程序人生:工作、生活、梦想
    HDU4756+Prim
    两分钟让你明白cocos2dx的屏幕适配策略
    Expected authority at index 7: hdfs://
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13848907.html
Copyright © 2020-2023  润新知