java.lang.IllegalArgumentException: Wrong FS://expected: file:///
2017-08-08 18:20
1456 查看
有错误提示file:///的提示信息是想需要本地文件系统(file:///为本地文件系统标识),代码无法识别HDFS文件系统,需要在Configuration中配置相应的参数。
如何来配置Configuration参数?
使用hadoop-2.6.0(因为我用的是apache-hadoop-2.6.0版本)的core-site.xml(/HADOOP_HOME/etc/hadoop/)的fs.defaultFS参数:
fs.defaultFS的vaue为hdfs://hadoopmaster:9000 在这里hadoopmaster为承载hadoop-2.6.0的linux系统(centOS-7.2)主机名称(hostname),
在centOS-7.2系统下设置hostname与IP映射:
所以,在此hostname与ip(192.168.184.99)是等价的
言归正传!!!
在程序中,把core-site.xml的fs.defaultFS参数配置给Configuration即可。
修改后的程序:
package org.hadoop.hdfs; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class ExeHDFS { private String hdfsPath = "hdfs://192.168.184.99:9000/haichuan/"; public static void main(String[] args) throws Exception { ExeHDFS exeHDFS = new ExeHDFS(); exeHDFS.testCreate(); } // 创建HDFS文件 public void testCreate() throws Exception { Configuration conf = new Configuration(); //使用hadoop的core-site.xml中的fs.defaultFS参数,防止Wrong FS: hdfs:.......file:/// 错误异常 conf.set("fs.defaultFS", "hdfs://192.168.184.99:9000"); byte[] buff = "hello world!".getBytes(); FileSystem hdfs = FileSystem.get(conf); Path dst = new Path(hdfsPath + "hello.txt"); FSDataOutputStream outputStream = null; try { outputStream = hdfs.create(dst); outputStream.write(buff, 0, buff.length); } catch (Exception e) { e.printStackTrace(); } finally { if (outputStream != null) { outputStream.close(); } } FileStatus files[] = hdfs.listStatus(dst); for (FileStatus file : files) { System.out.println(file.getPath()); } } }
相关文章推荐
- Hbase java.lang.IllegalArgumentException: Wrong FS file://......expected:hdfs://...
- java.lang.IllegalArgumentException: Wrong number of arguments; expected 0, got 1
- java.lang.IllegalArgumentException: Wrong FS: hdfs://localhost:9000/out, expected: file:///
- java.lang.IllegalArgumentException: Wrong arguments. new for target java.lang.reflect.Constructor expected=[java.net.URI] actual
- hadoop程序问题:java.lang.IllegalArgumentException: Wrong FS: hdfs://.... expected file:///
- java.lang.IllegalArgumentException: Wrong FS: hdfs://localhost:54310/user/Hadoop/b, expected: file:/
- java.lang.IllegalArgumentException: Wrong FS: expected: file:/// – Hadoop
- hadoop程序问题:java.lang.IllegalArgumentException: Wrong FS: hdfs:/ expected file:///
- hadoop程序抛出异常:java.lang.IllegalArgumentException: Wrong FS: hdfs:/ expected file:///
- java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 1 fields but
- Hadoop 问题java.lang.IllegalArgumentException Wrong FS: hdfs://192.168
- Caused by: java.lang.IllegalArgumentException: Wrong FS: hdfs:// :9000/ expected: hdfs:// :9000
- JMeter学习-027-JMeter参数文件(脚本分发)路径问题:jmeter.threads.JMeterThread: Test failed! java.lang.IllegalArgumentException: File distributed.csv must exist and be readable解决方法
- java.lang.IllegalArgumentException: Wrong state class
- Java反射异常:java.lang.IllegalArgumentException: wrong number of arguments
- java反射 java.lang.IllegalArgumentException: wrong number of arguments
- 解析Java反射java.lang.IllegalArgumentException: wrong number of arguments
- java.lang.IllegalArgumentException: Wrong state class, expecting View State but received
- java.lang.IllegalArgumentException: Wrong state classs
- java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class andro