一、导入依赖包
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