在Windows下的idea中访问HDFS报错 Could not locate executable null\bin\winutils.exe

18/09/08 20:18:33 ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
    at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:379)
    at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:394)
    at org.apache.hadoop.util.Shell.<clinit>(Shell.java:387)
    at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:80)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2823)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2818)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2684)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:373)
    at org.apache.hadoop.fs.FileSystem$1.run(FileSystem.java:162)
    at org.apache.hadoop.fs.FileSystem$1.run(FileSystem.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:159)
    at ls.hdfs.HDFSMain.main(HDFSMain.java:28)

 

解决方案:

在windows下解压Hadoop按照包,并且把winutils.exe放入解压包的bin目录下

百度云下载winutils链接

在Windows下的idea中访问HDFS报错 Could not locate executable null\bin\winutils.exe

最后在程序配置一下环境变量即可

System.setProperty("hadoop.home.dir", "D:\\hadoop\\hadoop-2.7.3");