Since \
is used as an escape character (for instance \n
= new line and \t
= tab) we need to write \\
to mean a single \
when placing this character in a String.
This issue does not exist with a forward slash /
For linux directories the forward slash /
is used; windows uses the backslash. Writing OS independent code could be a pain, but it's not an issue. Just use the forward slash when dealing with files and Java automagically translates it for you to the correct OS specific format.
For instance C:/Users/Owner/Documents
becomes C:\Users\Owner\Documents
on windows.
Or you could write "C:\\Users\\Owner\\Documents"
but the simple forward slash format looks simpler.