I have a file which contain several paths, like
public File(String parent, String child)
file xy located under /system/exampleProgram/config.config has the following content:
i want to resolve these to:
So, I am going to assume that you have access to the path of the file you opened (either via
File.getAbsolutePath() if it was a File descriptor or via a regex or something)...
Then to translate your relative paths into absolute paths, you can create new File descriptions with your opened file, like so:
File f = new File(myOpenedFilePath); File g = new File(f, "./extensions"); String absolutePath = g.getCanonicalPath();
When you create a file with a
File object and a
String, Java treats the
String as a path relative to the
File given as a first argument.
getCanonicalPath will get rid of all the redundant
.. and such.
Edit: as Leander explained in the comments, the best way to determine whether the path is relative or not (and thus whether it should be transformed or not) is to use