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);
}
来源:CSDN
作者:mqingo
链接:https://blog.csdn.net/mqingo/article/details/104022701