1
Hello, I am making a program in java in which I need to open a file and read it. However when I am trying to put the file path, it does not find such file and so I get Null Pointer Exception error. The code is as follows::
public File[] returnFiles()
{
File f = new File("/tests");
File[] filesArray = f.listFiles();
return filesArray;
}
Could someone tell me why I’m not able to find the file in this directory? Note: I am using Netbeans IDE, they say it must be his problem because it is not being found.
From now on, thank you.
So the way is this same "/tests". Or I would have to put the way from the root?
– Igor Nunes
It is a subfolder of the entire project: Interpreter/tests
– Igor Nunes
If you present the relative path as in the source, netbeans will search, by default, for the folder at the project root. Ex.:
NetbeansProjects/seuProjeto/tests
, if you don’t have it that way, you need to go the whole way.– user28595
Remembering that she is located in the Desktop. Would that?
– Igor Nunes
Diego, I did the step I said. But you accuse the same mistake.
– Igor Nunes
Add the full stack of errors to see if the problem is on the mentioned line.
– user28595
Diego, I discovered the mistake. Is that I should put the way from the home. Silly mistake here, but thanks for having helped.
– Igor Nunes
That’s what I told you about the relative and absolute way (complete to the root). :)
– user28595
Yeah, I didn’t get your sentence right. Sorry! rs
– Igor Nunes
No problems, handling java file system sometimes fills the bag with these same kkkk nullpointer
– user28595
I agree, kkkkkkkkkk.
– Igor Nunes