java: new File(“”, “name”) != new File(“name”) ? (file constructor with empty string)

后端 未结 5 894
野趣味
野趣味 2021-01-20 22:55

Noticed this today.

Given that a file named \"existing\" exists in the PWD of a java process (windows).

new File(\"existing\").exists() => true
         


        
5条回答
  •  余生分开走
    2021-01-20 23:24

    This is what's happening. But I agree because this is confusing

    new File("", "test").getAbsolutePath() => /test
    new File(".", "test").getAbsolutePath() => ${pwd}/test
    

    I have no idea why this is the case because I had assumed it would also be pwd for the first one.

提交回复
热议问题