java代码操作HDFS文件
?
/**
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
?
? ?
* @param args
* @throws Exception?
*/
public static void main(String[] args) throws Exception {
String HDFS = "hdfs://hadoop0:9000";///stu.txt
final FileSystem fileSystem = FileSystem.get(new URI(HDFS), new Configuration());
?
System.out.println(fileSystem.getDefaultBlockSize());
System.out.println(fileSystem.getStatistics());
?
? ? ? ? ? ? ? ? //打印某一路径下面的文件信息
FileStatus[] ?files = fileSystem.listStatus(new Path("/"));
for (FileStatus fileStatus : files) {
System.out.println(fileStatus.getPath());?
}
? ? ? ? ? ? ?//未完待补充,拿到fileSystem后面根据其API进行展开
? ?fileSystem.printStatistics() ;
?
}
原文:http://gaojingsong.iteye.com/blog/2288735