代码:
@Beforepublic void init() throws URISyntaxException, IOException {URI uri = new URI("hdfs://master:9000");// 创建一个配置文件Configuration entries = new Configuration();// 获取到了客户端对象
// entries.set("dfs.replication","2");fs = FileSystem.get(uri, entries);}@Testpublic void testFile() throws IOException{FileStatus[] fileStatuses = fs.listStatus(new Path("/"));for (FileStatus fileStatus : fileStatuses) {if (fileStatus.isFile()) {System.out.println("这是一个文件"+fileStatus.getPath().getName());}else {System.out.println("这是一个目录" + fileStatus.getPath().getName());}}}
效果: