Reputation: 679
I cant seem to get file IO to work within netbeans
public static void main(String[] args) throws IOException
{
System.out.println("File Location: "+ System.getProperty("myFile.txt"));
//File file = new File("myFile.txt");
}
I get an exception for this.
Exception in thread "main" java.lang.NullPointerException
And output:
File Location: null
without the System.getProperty
and I get the FileNotFoundException
java.io.FileNotFoundException: myFile.txt (The system cannot find the file specified)
The file itself is in the source directory of the project and also shows up in the IDE under the Source Packages > myproject> myFile.txt
Any reason why its not finding the file or any suggestions?
Thanks
Upvotes: 1
Views: 845
Reputation: 209112
File should be placed here if you're calling it like this "myFile.txt"
MyProject (project root)
myFile.txt
src
Upvotes: 2