First, your code seems correct, the path will be relative. It may depend on your system if /
is the correct separator, you may also need //
instead of /
but that is another story.
The easy and up-to-date answer: Don't use File
at all.
The new I/O library of Java (NIO) is able to do all that for you, platform independent. It revolves around the classes Path, Paths and Files.
You create a path to your file by using:
Paths.get("path", "to", "file");
It will dynamically select the correct separators for your current system.
And you read it using methods from Files
. For example a demo listing all contents of that file:
Path theFile = Paths.get("path", "to", "file");
Files.lines(theFile).forEach(System.out::println);
If you later need to use older methods which require a File
object you can simply use the Path#toFile
method (documentation).
Note that a relative path will always be relative to where your program has started. You can always check where you currently are by using:
System.out.println(System.getProperty("user.dir"));