前面我们讲了hadoop的httpFS访问,今天讲hadoop的第三种访问方式:JavaAPI
通过shell操作的也可以通过JavaAPI操作
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
public class HDFSTest {
public static void main(String[] args)throws Exception{
Configuration conf = new Configuration();
FileSystem fileSystem = FileSystem.newInstance(new URI("hdfs://192.168.1.91:9000"),conf);
// fileSystem.mkdirs(null);//文件夹
// fileSystem.delete(null);//删除
// fileSystem.open(null);//打开文件
// fileSystem.create(null);//上传文件
// fileSystem.listStatus(files);//查看列表
System.out.println(fileSystem);
}
}