`

异常java.lang.IllegalArgumentException: Wrong FS: hdfs:/, expected: file:///

阅读更多

 

在hadoop-2.2.0版本中对hdfs进行简单的测试操作,代码如下所示

Configuration conf = new Configuration();
try {
	FileSystem fs = FileSystem.get(conf);
	Path f = new Path("hdfs:///dfs_operator.txt");
	FSDataOutputStream os = fs.create(f, true);
	int i = 0;
	for (i = 0; i < 10; ++i)
		os.writeChars("test");
	os.close();
} catch (IOException e) {
	e.printStackTrace();
}

 

 执行报错信息如下:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.IllegalArgumentException: Wrong FS: hdfs:/, expected: file:///
        at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:642)
        at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:69)
        at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:419)
        at org.apache.hadoop.fs.ChecksumFileSystem.mkdirs(ChecksumFileSystem.java:584)
        at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:437)
        at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:424)
        at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:905)
        at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:886)
        at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:783)
        at com.ailk.hadoopdemo.DFSOperator.main(DFSOperator.java:22)
        ... 5 more

 解决方法一:

// explicitely add other config files// PASS A PATH NOT A STRING!
 conf.addResource(newPath("/home/hadoop/conf/core-site.xml"));

解决方法二:

    把hadoop集群上的core-site.xml和hdfs-site.xml放到工程的src目录下

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics