java.nio.file不存在,包java.nio.file不存在

I'm working out how to compile java from command line at the moment. Here's what I've got:

Here's what I've got:

/myjava/compile.cmd

/myjava/src/a_pack/HelloWorld.java

/myjava/src/b_pack/Inner.java

/myjava/src/b_pack/Inner2.java

/myjava/bin

HelloWorld:

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'm compiling this with javac -d bin -sourcepath -src src/a_pack/HelloWorld.java

and this works fine.

Now my understanding is, that because the HelloWorld.java references the other packages in it's import statements, then javac goes and compiles those.

And I'm guessing that for all the java packages, javac has them internally or something.

Anyway -

if I add the following import line to HelloWorld.java

import java.nio.file.Files;

it fails with

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 here? Why are some java packages good and some not?

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值