\ or / for path | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

\ or / for path

Have difference? I know the back-slash need escape: "\\folder\\subfolder\\file.txt" "/folder/subfooder/file.txt" There any difference? Exist some code that run one and not another? Because I use both, both works aleays and I never know why exist both.

22nd Oct 2020, 3:32 AM
Marcelo Anjos
Marcelo Anjos - avatar
1 Answer
0
As far as I know, java will replace delimiters according to operating system program runs on. So, if you will create path "/home/file.txt", if program runs on Windows, path will look like "\home\file.txt" The only thing you need to consider is that, for example, path "/folder/subfolder/file.txt" is considered absolute in Linux(/ is root folder) and relative in Windows (because it does not start with drive letter.)
22nd Oct 2020, 10:13 AM
Aleksandrs
Aleksandrs - avatar