Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://week01:9000/aa/test.

*爱你&永不变心* 提交于 2020-01-26 03:30:25

hadoop程序问题,出现

Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://week01:9000/aa/test.txt , expected: file:/// 

解决方法是:

①把core-site.xml文件和hdfs-site.xml文件放到src下即可。

②在代码中设置参数,设置完参数后,注意权限问题。

conf.set("fs.defaultFS", "hdfs://week01:9000");

设置完参数后,运行,会出现权限不足的问题:

此时,需要设置权限。

找到"Run As"------>"Run Configurations..."------>"Arguments",在VM arguments中添加 

-DHADOOP_USER_NAME=hadoop

设置完后,重新运行即可。

 

 

上传文件代码如下:

/**
	 * 上传文件
	 * @throws IOException 
	 */
	@Test
	public void upload() throws IOException{
		//拿到hdfs的客户端
		Configuration conf = new Configuration();
       //conf.set("fs.defaultFS", "hdfs://week01:9000");
		
		FileSystem fs = FileSystem.get(conf);
		
		
		//上传的地方
		Path  dst=new Path("hdfs://week01:9000/aa/test.txt");
		
		FSDataOutputStream os = fs.create(dst);
		
		//本地文件路径
		FileInputStream is = new FileInputStream("c:/test.txt");
		
		IOUtils.copy(is, os);
	}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!