Hadoop—— 2.java编程1

一、导入依赖包
hadoop/share/hadoop/common 
hadoop-common-xxxx.jar
hadoop-nfs-xxx.jar
hadoop/share/hadoop/hdfs/
hadoop-hdfs-client.xx.jar
/usr/local/hadoop/share/hadoop/hdfs
hadoop-hdfs-xxx.jar
hadoop-hdfs-nfs-xxx.jar
hadoop/share/hadoop/common/lib
所有JAR包
/usr/local/hadoop/share/hadoop/hdfs/lib
所有JAR包
二、eclipse新建文件编译

[root@master conf.d]# hdfs dfs -mkdir /test
[root@master conf.d]# hdfs dfs -touch /test/1.txt
[root@master conf.d]# hdfs dfs -ls /test
Found 1 items
-rw-r–r-- 1 root supergroup 0 2020-02-09 21:42 /test/1.txt

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

public class HDFSFileExist {
    public static void main(String[] args){
        try {
            String fileName = "/test/1.txt";
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS","hdfs://master:9000");
            conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem");
            FileSystem fs = FileSystem.get(conf);
            if(fs.exists(new Path(fileName))){
                System.out.println("file exist!");
            }else{
                System.out.println("file not exist");
            }


        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

在这里插入图片描述

在这里插入图片描述

https://www.zifangsky.cn/1294.html

https://www.zifangsky.cn/1292.html

————Blueicex 2020/2/9 21:35 blueice1980@126.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值