Package Java nio. File does not exist
I'm studying how to compile Java. Java from the command line This is what I got:
This is what I got:
/myjava/compile.cmd /myjava/src/a_pack/HelloWorld.java /myjava/src/b_pack/Inner.java /myjava/src/b_pack/Inner2.java /myjava/bin
Hello, world:
package a_pack; import b_pack.Inner; import b_back.Inner2; import java.util.ArrayList; import java.util.Iterator; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello,World"); Inner myInner = new Inner(); myInner.myInner(); Inner2 myInner2 = new Inner2(); myInner2.myInner(); ArrayList myArray = new ArrayList(); myArray.add(1); myArray.add(2); myArray.add(3); Iterator itr = myArray.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } } }
Inner. java
package b_pack; public class Inner { public void myInner() { System.out.println("Inner Method"); } }
Inner2. java
package b_pack; public class Inner2 { public void myInner() { System.out.println("SecondInner"); } }
I am using javac - D Bin - sourcepath - SRC Src / A_ pack / HelloWorld. Compile it in Java, which is easy to use
Now my understanding is, because HelloWorld Java references other packages in its import statement, and then javac compiles them And I guess for all Java packages, javac is inside or something else
Anyway – if I add the following import line to HelloWorld java
import java. nio. file. Files;
It failed
D:\.....\myjava>javac -d bin -sourcepath src src/a_pack/HelloWo rld.java src\a_pack\HelloWorld.java:8: package java.nio.file does not exist import java.nio.file.Files; ^ 1 error
What's the story? Why are some Java packages good and some bad?
Solution
Java NiO was introduced in Java 7 Compilers from earlier versions of JDK will monitor any code that contains these NiO classes You need to upgrade to JDK 7 or later