标签:rup throws 文件系统 false create else use div oop
package test.hdfs; import java.io.IOException; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; /* * @authr:Kouch * * 功能:变成实现判断hdfs上文件是否存在; * * 实现:调用hadoopAPI; * */ public class IsExsit { //main public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { //配置类 Configuration conf=new Configuration(); //模拟路径; String url="hdfs://localhost:9000/user/kouch/input"; //文件系统对象 FileSystem fs=FileSystem.get(URI.create(url), conf); if(isExsit(fs,url)) { System.out.println(url+"存在"); }else { System.out.println(url+"不存在"); } } //判断方式 public static boolean isExsit(FileSystem fs,String path) { boolean is=false; try { is=fs.exists(new Path(path)); } catch (IllegalArgumentException | IOException e) { e.printStackTrace(); } return is; } }
标签:rup throws 文件系统 false create else use div oop
原文地址:https://www.cnblogs.com/floakss/p/11455801.html