找不到包 java.nio.file
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20029271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find package java.nio.file
提问by H?kon H?gland
My java compiler cannot find the java.nio.file
package. Consider:
我的 java 编译器找不到java.nio.file
包。考虑:
import java.nio.file.*;
public class Test {
public static void main(String[] args) {
Path currentRelativePath = Paths.get("");
}
}
compiling with
编译
bash$ javac Test.java
gives
给
Test.java:1: package java.nio.file does not exist
import java.nio.file.*;
^
Test.java:5: cannot find symbol
symbol : class Path
location: class Test
Path currentRelativePath = Paths.get("");
^
Test.java:5: cannot find symbol
symbol : variable Paths
location: class Test
Path currentRelativePath = Paths.get("");
^
3 errors
I am using Ubuntu 12.04, and I think I have JDK 7 installed (see: package java.nio.file does not exist)
我使用的是 Ubuntu 12.04,我想我已经安装了 JDK 7(请参阅:包 java.nio.file 不存在)
bash$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
采纳答案by ljgw
It is entirely possible that you have java
1.7, but javac
1.6 or even 1.5
完全有可能你有java
1.7,但javac
1.6 甚至 1.5
maybe you can use
也许你可以使用
sudo update-alternatives --config javac
to configure it. If you cannot choose 1.7, then you need to upgrade your JDK package.
来配置它。如果你不能选择 1.7,那么你需要升级你的 JDK 包。
回答by Peter Lawrey
I would check
我会检查
javac -version
as you might not have Java 7 JDK installed correctly and so only java
has been, possibly one the JRE.
因为您可能没有正确安装 Java 7 JDK,所以只有java
一个,可能是 JRE。
回答by Ajeesh
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.
Java NIO 是在 Java 7 中引入的。来自 JDK 早期版本的编译器将阻止包含这些 NIO 类的任何代码。您需要升级到 JDK 7。
回答by Ali Hashemi
Make sure that you've passed the correct address for JAVA_HOME
and PATH
which is Java 7 installation directories.
请确保您已经通过正确的地址JAVA_HOME
和PATH
它是Java 7的安装目录。
回答by David
I had the same issue. I use Eclipse. There is an option to set JDK Compliance. I set from 1.5 to 1.8 and recompiled the projects. It is fine now. I suggest to set globally and disable this option on project level.
我遇到过同样的问题。我使用 Eclipse。有一个选项可以设置 JDK 合规性。我从 1.5 设置到 1.8 并重新编译项目。现在很好。我建议全局设置并在项目级别禁用此选项。