Creating a path between two paths in Java using the Path class

后端 未结 4 1975
梦如初夏
梦如初夏 2020-12-11 15:05

What does exactly mean this sentence from this oracle java tutorial:

A relative path cannot be constructed if only one of the paths includes a root

4条回答
  •  一生所求
    2020-12-11 15:59

    I did some tests of your example. Actually the exception you are mentioning appears only when one of the paths contains root and the other not (exactly like the sentence says) E.g:

    • /home/sally/bar
    • home

    It works ok if both paths contain roots. The "system dependent" means probably such case on Windows:

    • C:\home
    • D:\home\sally\bar

    Above gives following exception:

    java.lang.IllegalArgumentException: 'other' has different root
    

    You will never face something like this (exception for both paths containing root - absolute paths) on Unix

提交回复
热议问题