1

I just made a small program that saves a path into an INI file.

But on the output, the path is written like so :

C:\\Windows

I want it to be put like so :

C:\Windows

I tried many way with the string.replace but one backslash gives error and putting 4 doesn't makes 1 backslashes in the output but 4...

I am out of ideas.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • 2
    Why do you need to write using \ ? This file will be read by some Windows (native) application? – davidbuzatto Aug 17 '12 at 01:50
  • If the INI file is a Properties file, you don't have the choice: you are stuck with the predefined rules for properties files, which dictate backslashes as escape characters, and therefore double backslashes to represent epreal backslashes. – user207421 Aug 17 '12 at 04:19

3 Answers3

3

Using the File Separator will give you the platform independent character and you wont have to escape it.

See this question for all the different options.

Community
  • 1
  • 1
n00begon
  • 3,503
  • 3
  • 29
  • 42
1

Here's an example to get the double backslash:

System.out.println("File path = C:\\"+"\\"+"Windows");

Would output this:

C:\\Windows
Hartleben
  • 35
  • 2
1

As the OP is using Java and I'm assuming that this INI file will be used by a Java application, I don't think that he needs to write the path using backslashes, since Java will convert normal slashes to backslashes in Windows using the File Separator under the hood. So, just write C:/Windows or C:/some/path/here and it will work normally.

davidbuzatto
  • 9,207
  • 1
  • 43
  • 50