delete HDFS file or directory - Java Big Data

Java examples for Big Data:HDF

Description

delete HDFS file or directory

Demo Code

package Hdfs;/*w w  w.ja  v a  2  s. c  o m*/

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;


public class DeleteFile {
    public static void main(String[] args) {
        String uri = "hdfs://neusoft-master:9000/user/root/test1";
        Configuration conf = new Configuration();
        try {
            FileSystem fs = FileSystem.get(URI.create(uri), conf);
            Path delPath = new Path(
                    "hdfs://neusoft-master:9000/user/root/test1");
            boolean isDeleted = fs.delete(delPath, false);
            //boolean isDeleted = fs.delete(delPath,true);//????
            System.out.println(isDeleted);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials