Joe
Joe

Reputation: 795

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

Upvotes: 4

Views: 15181

Answers (2)

Chris Dail
Chris Dail

Reputation: 26069

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

Upvotes: 11

halfdan
halfdan

Reputation: 34274

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.

Upvotes: 3

Related Questions