Java api 从hdfs上下载文件失败,报错null指针,怎么回事啊
来源:3-11 Java API操作HDFS文件系统
聂成阳
2018-04-11
@Test
public void copyToLocalFile() throws Exception {
Path localPath = new Path("C:\\Users\\18811\\Desktop");
Path hdfsPath = new Path("/hello.txt");
fileSystem.copyToLocalFile(hdfsPath, localPath);
}
java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1010)
at org.apache.hadoop.util.Shell.runCommand(Shell.java:505)
at org.apache.hadoop.util.Shell.run(Shell.java:478)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:738)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:831)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:814)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:664)
at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:506)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:462)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:428)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:920)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:901)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:798)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:368)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:341)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:292)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:2014)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1983)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1959)
at com.imooc.hadoop.hdfs.HDFSApp.copyToLocalFile(HDFSApp.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
5回答
-
一个很坏的好人
2018-11-04
src文件位于此文件系统下,dst位于本地磁盘上。将其从远程文件系统复制到本地dst名称。delSrc指示src是否会被删除。useRawLocalFileSystem指示是否使用RawLocalFileSystem作为本地文件系统。RawLocalFileSystem不是校验和,所以它不会在本地创建任何crc文件。
delSrc : 是否删除src
useRawLocalFileSystem:是否使用RawLocalFileSystem作为本地文件系统。
30 -
Michael_PK
2018-04-17
window s环境的问题,你们如果没有Mac或者想少遇到点问题,建议在VM里面安装一个idea,直接开发,就不会有这些乱七八糟的问题了
10 -
慕的地6929991
2018-04-17
遇到同样问题,网上找的答案,试了下好用了https://blog.csdn.net/u011478909/article/details/51874002
解决方法:将fs.copyToLocalFile( hdfsPath,localPath);改为fs.copyToLocalFile( false,hdfsPath,localPath,true);
原因:不理解,但加上这两个后确实可以下载
112018-05-18 -
聂成阳
提问者
2018-04-17
我也是通过这个方法解决的,谢谢啊
00 -
Michael_PK
2018-04-11
据说Windows上API操作HDFS都有些问题,需要在本地添加一个common的东西才行
00
相似问题