$echo "This is for MyHDFSCat" > test.txt
$bin/hadoop fs -put test.txt /test.txt
JAVA
...
public class MyHDFSStat extends Configured implements Tool
{
public int run(String[] args) throws Exception{
String url = null;
if (args.lrlength > 0){
uri = args[0];
}
Configuration conf = this.getConf();
FileSystem fs=FileSystem.get(URI.create(uri),conf);
FileStatus status = fs.getFileStatus(new Path(uri));
System.out.printf("path:%s\n",status.getPath());
System.out.printf("length:%d\n",status.getLen());
return 0;
}
}
public static void main(String[] args) throws Exception{
int exitCode() = ToolRunner.run(new MyHDFSStat(), args);
System.exit(exitCode);
}
...
JAVA
myhdfsstat.jar
$bin/hadoop jar myhdfsstat.jar com.cisco.MyHdfsStat hdfs:///test.txt
path: hdfs://master:9000/test.txt
length: 18
This is for MyHDFSCat = 18+3