Converting Relative Paths to Absolute Paths

前端 未结 9 1271
北荒
北荒 2020-12-05 04:14

I have an absolute path to file A.

I have a relative path to file B from file A\'s directory. This path may and will use \"..\" to go up the directory structure in

9条回答
  •  臣服心动
    2020-12-05 05:05

    If I get your problem right, you could do something like this:

    File a = new File("/some/abs/path");
    File parentFolder = new File(a.getParent());
    File b = new File(parentFolder, "../some/relative/path");
    String absolute = b.getCanonicalPath(); // may throw IOException
    

提交回复
热议问题