File directory

Asked

Viewed 51 times

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?

  • It is a subfolder of the entire project: Interpreter/tests

  • 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.

  • Remembering that she is located in the Desktop. Would that?

  • Diego, I did the step I said. But you accuse the same mistake.

  • Add the full stack of errors to see if the problem is on the mentioned line.

  • Diego, I discovered the mistake. Is that I should put the way from the home. Silly mistake here, but thanks for having helped.

  • That’s what I told you about the relative and absolute way (complete to the root). :)

  • Yeah, I didn’t get your sentence right. Sorry! rs

  • No problems, handling java file system sometimes fills the bag with these same kkkk nullpointer

  • I agree, kkkkkkkkkk.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.