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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With