import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;public class isFIleExist { public static void main(String[] args) { try { String filename = "test"; //经典配置四件套 Configuration conf = new Configuration(); conf.set("fs.defaultFS","hdfs://localhost: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("文件或目录存在"); }else{ System.out.println("文件或目录不存在"); } fs.close(); } catch (Exception e) { e.printStackTrace(); } }}