Converting Relative Paths to Absolute Paths

前端 未结 9 1259
北荒
北荒 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:04

    From your question, if i could get it right, you are looking to get abolute path from relative path, then you can do following.

    File b = new File("../some/relative/path");
    String absolute = b.getCanonicalPath(); // may throw IOException
    

    or shorthand notation can be,

    String absolute = new File("../some/relative/path").getCanonicalPath();
    

提交回复
热议问题