Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find package java.nio.file

Tags:

java

nio

My java compiler cannot find the java.nio.file package. Consider:

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 )

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)
like image 724
Håkon Hægland Avatar asked Nov 17 '13 09:11

Håkon Hægland


2 Answers

It is entirely possible that you have java 1.7, but javac 1.6 or even 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.

like image 138
ljgw Avatar answered Oct 15 '22 21:10

ljgw


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.

like image 44
Ajeesh Avatar answered Oct 15 '22 23:10

Ajeesh