Difference between C: and C:/

后端 未结 2 1577
慢半拍i
慢半拍i 2021-01-18 10:49

I was just reading some java book and making some small programs for practice, I created a small code to get information about the path I entered, and the code is:



        
2条回答
  •  囚心锁ツ
    2021-01-18 11:18

    This is not really a java question, but a windows/dos question.

    The explanation comes down to the old dos command for switching drives.

    Typing a drive letter followed by a colon is a command to change drives in dos, therefore the 'command' C: does nothing since your working dir is already on the C drive. The 'directory' returned by the native interface to the JRE is the same as if you used the path "", ie your working directory.

    On the other hand, add a slash and it is a proper path, to the root of your C drive, therefore your JRE is given this directory by the native interface.

    If you go to a dos command (windows>run>cmd) and type in C: you will see that it accepts the command but does not change directory, unless of course you are currently on a different drive at the time.

    hope that helps.

提交回复
热议问题