四种获取FileSystem

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

public class fileSystem {
	public static void main(String [] args) throws IOException, URISyntaxException {
		filedemo1();
		filedemo2();
		filedemo3();
		filedemo4();
		
	}
	public static void filedemo1() throws IOException {
		Configuration conf = new Configuration();//创建Configuration对象
		conf.set("fs.defaultFs,","hdfs://Master:9000");//指定获取文件类型:分布式还是本机
		FileSystem file = FileSystem.get(conf);//获取指定文件系统
		System.out.println(file);
			
	}
	public static void filedemo2() throws IOException, URISyntaxException {

		FileSystem file = FileSystem.get(new URI("hdfs://Master:9000"),new Configuration());//推荐使用这种方式
		System.out.println(file);
			
	}
	public static void filedemo3() throws IOException, URISyntaxException {
		Configuration conf = new Configuration();
		conf.set("fs.defaultFs,","hdfs://Master:9000");
		FileSystem file = FileSystem.newInstance(conf);//通过创建FilsSystem实例
		System.out.println(file);
	}
	public static void filedemo4() throws IOException, URISyntaxException {

		FileSystem file = FileSystem.newInstance(new URI("hdfs://Master:9000"),new Configuration());
		System.out.println(file);
			
	}
}

运行结果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值