用命令行bin/Hadoop fs -rm(r) 可以删除hdfs上的文件(夹)
用HDFS的API也是可以的。如下:
import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class FileDelete { public static void main(String[] args) throws Exception { if(args.length != 1){ System.out.println("Usage filedelete <target>"); System.exit(1); } Configuration conf = new Configuration(); FileSystem hdfs = FileSystem.get(URI.create(args[0]),conf); hdfs.delete(new Path(args[0]),false); } }