程序:
package com.fish.first;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class firstHadoop {
private static String PATH = "hdfs://Hadoop2-Master:9000/";
public static void main(String[] args) throws Exception {
FileSystem fs = FileSystem.get(new URI(PATH), new Configuration());
//浏览
FileStatus[] status = fs.listStatus(new Path("/hmbbs_logs"));
for (FileStatus l : status) {
String isDir = l.isDirectory() ? "文件夹" : "文件";
String permission = l.getPermission().toString();
short replication = l.getReplication();
long len = l.getLen();
String path = l.getPath().toString();
System.out.println(isDir+"\t"+permission+"\t"+replication+"\t"+len+"\t"+path);
}
}
}
|
错误信息:
2015-01-22 10:06:36,117 WARN util.NativeCodeLoader (NativeCodeLoader.java:<clinit>(62)) - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2015-01-22 10:06:36,845 ERROR util.Shell (Shell.java:getWinUtilsPath(303)) - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:278)
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:300)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:293)
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:76)
at org.apache.hadoop.conf.Configuration.getTrimmedStrings(Configuration.java:1546)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:519)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:453)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:136)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2433)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:88)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2467)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2449)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:367)
at com.fish.first.firstHadoop.main(firstHadoop.java:15)
文件 rw-r--r-- 2 61084192 hdfs://Hadoop2-Master:9000/hmbbs_logs/access_2013_05_30.log
文件 rw-r--r-- 2 157069653 hdfs://Hadoop2-Master:9000/hmbbs_logs/access_2013_05_31.log
|
能得到结果:
文件 rw-r--r-- 2 61084192 hdfs://Hadoop2-Master:9000/hmbbs_logs/access_2013_05_30.log
文件 rw-r--r-- 2 157069653 hdfs://Hadoop2-Master:9000/hmbbs_logs/access_2013_05_31.log
请问有人解决过这种问题吗?我用的是hadoop2.2.0版。
|