hException in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://hadoop:9000/tadoop:

java代码如下: 

 FileSystem fs = FileSystem.get(conf);

        if (fs.exists(inputDir)) {
            throw new IOException(String.format("Input directory '%s' exists - please remove and rerun this example", inputDir));
        }

        OutputStreamWriter writer = new OutputStreamWriter(fs.create(new Path(inputDir, "input2.txt")));
            writer.write(JSON);

抛出异常如下:Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://hadoop:9000/test/input, expected: file:///

at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:381)
at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:55)
at org.apache.hadoop.fs.LocalFileSystem.pathToFile(LocalFileSystem.java:61)
at org.apache.hadoop.fs.LocalFileSystem.exists(LocalFileSystem.java:51)
at com.up366.json.mapreduce.ExampleJob.writeInput(ExampleJob.java:81)
at com.up366.json.mapreduce.ExampleJob.run(ExampleJob.java:104)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)

at com.up366.json.mapreduce.ExampleJob.main(ExampleJob.java:33)

解决方案:hadoop需要把集群上的core-site.xml和hdfs-site.xml放到当前工程下。

eclipse工作目录的bin文件夹下面因为是访问远程的HDFS 需要通过URI来获得FileSystem.

你可能感兴趣的:(hadoop)