用fs.copyToLocalFile( hdfsPath,localPath);下载hdfs的文件会报NullPointerException,具体报错为:
java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:)
at org.apache.hadoop.util.Shell.runCommand(Shell.java:)
at org.apache.hadoop.util.Shell.run(Shell.java:)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:)
at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:)
at hadoop.downFile.downloadFileorDirectoryOnHDFS(downFile.java:)
at hadoop.downFile.main(downFile.java:)
解决方法:将fs.copyToLocalFile( hdfsPath,localPath);改为fs.copyToLocalFile( false,hdfsPath,localPath,true);
原因:不理解,但加上这两个后确实可以下载