我有一个clouderquickstart容器,我尝试使用java应用程序获取hdfs下的文件列表;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.BasicConfigurator;
import java.io.IOException;
public class HdfsListing {
public static void main(String[] args) throws IOException {
BasicConfigurator.configure();
Configuration configuration=new Configuration();
configuration.set("fs.default.name","hdfs://172.17.0.2:9000");
FileSystem fs=FileSystem.get(configuration);
Path path=new Path("hdfs://172.17.0.2:9000/user");
FileStatus[] fsl=fs.listStatus(path);
for(FileStatus f:fsl) System.out.println("=======>"+f.getPath().getName());
}
}
当我运行该代码时,我在控制台中得到以下消息
7790 [main] DEBUG org.apache.hadoop.ipc.Client - The ping interval is 60000 ms.
7792 [main] DEBUG org.apache.hadoop.ipc.Client - Connecting to /172.17.0.2:9000
32439 [main] INFO org.apache.hadoop.ipc.Client - Retrying connect to server: 172.17.0.2/172.17.0.2:9000. Already tried 0 time(s); maxRetries=45
...
hadoop下的hosts文件
# 127.0.0.1 localhost
# ::1 localhost ip6-localhost ip6-loopback
# fe00::0 ip6-localnet
# ff00::0 ip6-mcastprefix
# ff02::1 ip6-allnodes
# ff02::2 ip6-allrouters
172.17.0.2 quickstart.cloudera quickstart
暂无答案!
目前还没有任何答案,快来回答吧!