hadoop程序问题:java.lang.IllegalArgumentException: Wrong FS: hdfs:/ expected file:///

Java代码如下:

  1. FileSystem fs = FileSystem.get(conf); 
  2. in = fs.open(new Path("hdfs://192.168.130.54:19000/user/hmail/output/part-00000")); 

抛出异常如下:

  1. Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://192.168.130.54:19000/user/hmail/output/part-00000, expected: file:/// 
  2.     at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:310) 
  3.     at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:47) 
  4.     at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:357) 
  5.     at org.apache.hadoop.fs.FilterFileSystem.getFileStatus(FilterFileSystem.java:245) 
  6.     at org.apache.hadoop.fs.ChecksumFileSystem$ChecksumFSInputChecker.<init>(ChecksumFileSystem.java:125) 
  7.     at org.apache.hadoop.fs.ChecksumFileSystem.open(ChecksumFileSystem.java:283) 
  8.     at org.apache.hadoop.fs.FileSystem.open(FileSystem.java:356) 
  9.     at com.netease.hadoop.HDFSCatWithAPI.main(HDFSCatWithAPI.java:23) 

解决方案:

hadoop需要把集群上的core-site.xml和hdfs-site.xml放到当前工程下。eclipse工作目录的bin文件夹下面


因为是访问远程的HDFS 需要通过URI来获得FileSystem.

原文地址:https://www.cnblogs.com/zhengrunjian/p/4650525.html