0

I've been doing some pretty typical coding projects for a CS class at school, and one or two of them involve reading files. I'm curious why the filepaths outputted by my Windows 7 machine and read by my Java IDE Eclipse use different facing slashes. For example C:\Users\jhobbie\Desktop\eclipse gives an error "invalid escape sequence" and I have to go in and switch all the slashes to C:/Users/jhobbie/Desktop/eclipse. I understand what the error message means, I'm just wondering why Windows would output (and I assume use?) different direction slashes than Java. Is there an alternate way of reading file names other than strings that allows this formatting?

Thanks!

jhobbie
  • 1,016
  • 9
  • 18
  • I didn't get the relation between your text and your header. – AlexS Jun 12 '14 at 15:09
  • the backslash \ is a reserved caracter in java. That's why it gives an error when you use it inadequately. If you want to use a backslash in a string you have to had another backslash \\. So the string for that extension using backslash would be: "C:\\Users\\jhobbie\\Desktop\\eclipse" – DCarochoC Jun 12 '14 at 15:15
  • Not really. I know that I should use forward slash, I'm just unclear why Windows gives me the address in a different way – jhobbie Jun 12 '14 at 15:26
  • 1
    Is this a programming question? In any case, a better discussion is available here: http://superuser.com/questions/176388/why-does-windows-use-backslashes-for-paths-and-unix-forward-slashes – oberlies Jun 12 '14 at 15:57

1 Answers1

0

Windows uses backslah as separator. The reason is historical: MSDOS 1.0 did use backslash and all other msdos and windows version use it for backwards compatibility. Although most Microsoft products should theoretically also accept slash.

AlexS
  • 5,295
  • 3
  • 38
  • 54