开发者社区> 问答> 正文

HDFS的API操作查看文件是否存在怎么做?

HDFS的API操作查看文件是否存在怎么做?

展开
收起
游客y244y7ln2rlpa 2021-12-07 06:37:09 842 0
1 条回答
写回答
取消 提交回答
  • 查看文件:通过“FileSystem.exists(Path f)”可以查看指定文件是否存在。

    具体代码如下:``` package HDFS.learnself;

    import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path;

    public class ifExists { public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException {

    //1.加载hdfs的配置文件 Configuration conf=new Configuration();

    //2.获取hdfs的操作对象 FileSystem fs=FileSystem.get(new URI("hdfs://hdp01:9000"), conf, "hdp02");

    //3.要查找的文件路径 Path File=new Path("/test/fur01.txt");

    //4.调用exists方法 boolean isExists=fs.exists(File); System.out.println(isExists); } }

    2021-12-07 06:38:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Boot2.0实战Redis分布式缓存 立即下载
CUDA MATH API 立即下载
API PLAYBOOK 立即下载