0

I wanted to know the difference between "\" and "/" used in file path in a java program and also the difference between "\" and "\" used in file path.

  • 1
    Does this answer your question? [Difference between forward slash (/) and backslash (\‌) in file path](https://stackoverflow.com/questions/38428561/difference-between-forward-slash-and-backslash-in-file-path) – avocadoLambda Jun 10 '20 at 04:07
  • Nothing. Java translated ``\`` to `/` on platforms where that is necessary (and vice-versa where ``\`` is required). I suggest using `/` because it's more readable. – Elliott Frisch Jun 10 '20 at 04:08

3 Answers3

1

/ is a linux and mac os based delimiter for traversing directories and files. \ is Windows based .

Sahil Garg
  • 167
  • 6
0

The difference is using on Linux OS or Window OS. In a Java program, you can use the file path in both two ways:

String s = "C:\\Users\\DEU1HC\\Desktop\\IntelliJ 2019.3.1\\bin";

or

String s = "C:/Users/DEU1HC/Desktop/IntelliJ 2019.3.1/bin";
-1

In the narrow scope of File IO, char \ is only thing that is allowed in path. Even in non-linux OS \ is used as path separator.

stackguy
  • 188
  • 5