package java.nio.file does not exist

…衆ロ難τιáo~ 提交于 2019-12-05 06:02:56

Java NIO was introduced in Java 7. Compilers from earlier versions of the JDK will baulk at any code that contains these NIO classes. You need to upgrade to JDK 7 or higher.

If you are on OSX, then check the JDK it is using...

$ cd /System/Library/Frameworks/JavaVM.framework/Versions
$ readlink /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
$ javac -version
javac 1.7.0_25

As you can see CurrentJDK is pointing to the wrong version. You can fix that by replacing the symlink.

cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo ln -fs /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents CurrentJDK

Credit goes to this blog post which saved me 5min of running dtrace.

pcjose

I came across this issue and found my JAVA_HOME environment variable was still pointing to the old java 1.6.

  • Running javac -version showed 1.7
  • Running java -version showed 1.7

etc…

On removing that environment variable, things compiled fine.

The Files class consists of only static methods. I'm not sure if this is why it can't be imported, but it does mean it doesn't need to be imported.

Edit: Just realized the package you specified is import java.nio.files.Files. The actual package is java.nio.file.Files; http://docs.oracle.com/javase/7/docs/api/java/nio/file/package-summary.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!