I have a directory pointed to by a File object called baseDir in which I keep most of my files.
I have a String f which may contain a relative filename, like “data.gz”, or an absolute filename like “/mnt/data.gz” (its specified in a config file).
In the event that f is relative, it should be assumed that the file specified is within baseDir, but if it is absolute then it should be treated accordingly.
How do I create a File object that points to the file represented by f?
I can think of hacky solutions to this (eg. if (f.startsWith("/")) ... but I’m hoping there is a “right way” to do this.
Oh, I tried using the File(File, String) constructor for the File object, but it doesn’t do what I need it to do.
You can try the following:
Be careful that the definition of absolute path is system dependent!