-6

I have following project structure:

src
--Main.java
--resources
----Users.txt

And I am trying to create a file from Main.java like that:

      File file = new File("resources/Users.txt");

However, I never succeed at doing so.

Why?

alegrowski
  • 261
  • 2
  • 3
  • 8
  • 1
    Any errors? If yes, then what? – dryairship Apr 07 '16 at 13:05
  • Actually no errors what so ever. The when I debug the file is null – alegrowski Apr 07 '16 at 13:06
  • 1
    `new File(...)` can never yield a null pointer. Please include a complete and minimal example. – E_net4 Apr 07 '16 at 13:08
  • 1
    If it is a regular file outside a .jar, you are using a relative path. That means, the path to the file is formed from the path where you are calling the file from + the relative path. To make it work, you should invoke java within src folder – Nadir Apr 07 '16 at 13:08
  • @Nadir, you are the one who helped. Thank you! Please, post this as an answer – alegrowski Apr 07 '16 at 13:19

1 Answers1

0

If it is a regular file outside a .jar, you are using a relative path. That means, the path to the file is formed from the path where you are calling the file from + the relative path. To make it work, you should invoke java within src folder

Nadir
  • 1,799
  • 12
  • 20