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 ShowFileStatus {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String uri = args[0];
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
Path file = new Path(args[0]);
FileStatus stat = fs.getFileStatus(file);
System.out.println(stat.getLen());
}
}
getFileStatus()
是FileSystem
类中的抽象方法,需要扩展FileSystem
类才能使用getFileStatus()
方法。但是在上面的代码中,我无需扩展
FileSystem
类就可以使用method。怎么样 ?我不明白吗?
最佳答案
使用FileSystem
类中提供的静态工厂方法获取FileSystem
类的实例时。它在内部创建自己的实现之一的实例。 FileSystem有许多可用的实现。
public static FileSystem get(URI uri, Configuration conf) throws IOException
现在基本上,您将调用提供的实现之一的
getFileStatus
方法。关于hadoop - 抽象方法的实现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32398721/