Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am new and learning 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 app I get the following error message:

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

The error displays on both of these lines.

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

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

Thank you, Joe

like image 220
Joe Avatar asked Dec 09 '22 04:12

Joe


2 Answers

Sounds like you are using a Java version 6 or lower. The java.nio.file package and classes were added as part of Java 7. Try running the following to verify you have Java 7 installed.

java -version
like image 192
Chris Dail Avatar answered Dec 11 '22 16:12

Chris Dail


You've got a small typo in your include. It should read:

import java.nio.file.StandardOpenOption;

The package java.nio.file.* should exist in Java SE 7. Please check whether you are really using the Java 7 Compiler.

like image 34
halfdan Avatar answered Dec 11 '22 16:12

halfdan