版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q435201823/article/details/86767162
需要注意的:
FileSystem.delete(Path f)方法以及过时不用了,建议使用FileSystem.delete(Path f, boolean recursive) 。
recursive为是否递归删除。
package hadoop.hdfs;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.jupiter.api.Test;
public class HDFSUtil {
@Test
public void del() throws IOException, InterruptedException, URISyntaxException{
//删除文件(夹)
Configuration conf=new Configuration();//加载配置
FileSystem fs = FileSystem.get(new URI("hdfs://Ubuntu01:9000/"),conf,"czq");//加载文件系统实例
fs.delete(new Path("/aa"),true);
}
}