Java error (package java.nio.file does not exist import java.nio.file. *;)

I am new to Java. I tried running the following application in Netbeans 7.

import java.io.*; import java.nio.file.*; import java.nio.file.StrandardOpenOption.*; public class FileOut { public static void main(String[] args) { Path file = Paths.get("C:\\Java\\Chapter.13\\Grades.txt"); String s = "ABCDF"; byte[] data = s.getBytes(); OutputStream output = null; try { output = new BufferedOutputStream(file.newOutputStream(CREATE)); output.write(data); output.flush(); output.close(); } catch (Exception e) { System.out.println("Message: " + e); } } } 

and when I compile the application, I get the following error message:

 package java.nio.file does not exist import java.nio.file.*; 

An error is displayed on both of these lines.

 import java.nio.file.*; import java.nio.file.StrandardOpenOption.*; 

What do I need to do to make this work? I would appreciate any help.

Thanks Joe

+4
source share
2 answers

It looks like you are using Java version 6 or lower. The java.nio.file package and classes were added as part of Java 7. Try the following to make sure you have Java 7 installed.

 java -version 
+10
source

You have a small typo in your inclusion. It should read:

 import java.nio.file.StandardOpenOption; 

The java.nio.file.* Package must exist in Java SE 7. Verify that you are actually using the Java 7 compiler.

+3
source

Source: https://habr.com/ru/post/1382202/


All Articles