Java代碼以下:java
- FileSystem fs = FileSystem.get(conf);
- in = fs.open(new Path("hdfs://192.168.130.54:19000/user/hmail/output/part-00000"));
拋出異常以下:apache
- Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://192.168.130.54:19000/user/hmail/output/part-00000, expected: file:///
- at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:310)
- at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:47)
- at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:357)
- at org.apache.hadoop.fs.FilterFileSystem.getFileStatus(FilterFileSystem.java:245)
- at org.apache.hadoop.fs.ChecksumFileSystem$ChecksumFSInputChecker.<init>(ChecksumFileSystem.java:125)
- at org.apache.hadoop.fs.ChecksumFileSystem.open(ChecksumFileSystem.java:283)
- at org.apache.hadoop.fs.FileSystem.open(FileSystem.java:356)
- at com.netease.hadoop.HDFSCatWithAPI.main(HDFSCatWithAPI.java:23)
解決方案:eclipse
hadoop須要把集羣上的core-site.xml和hdfs-site.xml放到當前工程下。eclipse工做目錄的bin文件夾下面oop
由於是訪問遠程的HDFS 須要經過URI來得到FileSystem.spa