Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import java.nio.file package

Im trying to listen to a directory for changes, then discovered java.nio.* was developed to handle efficiently such tasks and more. Then downloaded jdk1.7.0_02 from oracle and started eclipse with it. Then created new java project, tryed to implement some class from java.nio.file and Oh my eyes! "The import java.nio.file cannot be resolved". Do i have to find some .jar in the whole jdk1.7.0_02 directory that contains such package? or is something wrong with my classpath? Thank you in advance!!

like image 438
user1457150 Avatar asked Jul 05 '12 06:07

user1457150


People also ask

What is import Java NIO file paths?

Technically in terms of Java, Path is an interface which is introduced in Java NIO file package during Java version 7,and is the representation of location in particular file system.As path interface is in Java NIO package so it get its qualified name as java. nio. file.

What is Nio file in Java?

Core Java bootcamp program with Hands on practice Java NIO package provide one more utility API named as Files which is basically used for manipulating files and directories using its static methods which mostly works on Path object.

How do I create a NIO file?

In order to create a file with the nio package, we first need to set the path and then use the createFile() method from Files class. Creating files via the new nio package is the preferred option as the API is more intuitive. The above code example assumes the path src/test/resources already exists.


1 Answers

You've different version of JDKs. You just need to set JDK7/JRE7 version eclipse project. You may also select the Execution environment JRE to JavaSE 7 while creating a new project.

The JDK your projects use to compile, the version of the resulting class files, the JRE they used to execute and the JDK eclipse runs with are widely independent settings.

like image 153
KV Prajapati Avatar answered Oct 07 '22 00:10

KV Prajapati