Click here to Skip to main content
15,897,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I'm programming an application with Java in Eclipse and I use a input-file which is given with a path (p.e. C:\Java\Test-Application\config.ini).

When I debugg this application, this path is written as:
C:\\Java\\Test-Application\\config.ini

Why does that happen? I don't really understand, why there are double-backslashes instead of one.

Thx for your help.
Painjofshem
Posted

the \ is seen as an escape character so you need \\ to tell java it is \
 
Share this answer
 
Comments
Mehdi Gholam 3-Oct-11 5:04am    
my 5!
Simon Bang Terkildsen 3-Oct-11 5:11am    
What the hell, mine too ;)
epanjohura 3-Oct-11 5:05am    
hmmm okaay, but what can I do to remove this double-backslashes? I want to make it possible to copy a path and put it in a input-file without change this adding another backslash. I didn't find any settings to change, so I thought I could try to programm it by my self..
Simon Bang Terkildsen 3-Oct-11 5:11am    
You can't, it would be a serious bug if you could. The string would have changed and thus wouldn't be correct when it was reassigned to the variable.
epanjohura 3-Oct-11 5:15am    
hm, damn..
thanks a lot :)
That's because \ is an escape character[^], e.g. when you want a new line in your string you would write \r\n thus you have to write \\ for your string to contain the character \.
 
Share this answer
 
v2
Comments
epanjohura 3-Oct-11 5:07am    
thank you, but is there any possibility to change that? (my comment on solution 1)
Espen Harlinn 3-Oct-11 17:54pm    
5'ed!
'\' is a escape character
so to consider '\' in path as normal character and not escape character you need to use '\\'.
that why the debugger shows '\\'.
 
Share this answer
 
Comments
epanjohura 3-Oct-11 5:07am    
thank you, but is there any possibility to change that? (my comment on solution 1)
P.Salini 3-Oct-11 5:14am    
You cant remove it
Espen Harlinn 3-Oct-11 17:54pm    
5'ed!
if you are using the path string with "\\" in another file path related operation then it wouldn't be a problem, the VM does that translation for you. However, if the path string is to be used just as another string for some other purpose then you can [replace] "\\" with "\"...

Cheers
 
Share this answer
 
Comments
epanjohura 12-Oct-11 4:43am    
Thanks gladiatron for your answer, but I already got it :P
I.explore.code 12-Oct-11 5:07am    
ah! sorry my bad, didn't notice the "Solved" keyword against the question. No Problem mate, now you will never get stuck with this problem again ;)

Cheers...
epanjohura 12-Oct-11 5:11am    
doesn't matter ;)
Hi guys,

I know that "\" is an escape character, but is there really no possibility to read it as a "normal" character?

I wanted to read a path (which is read out in a string) character by character and check whether one is a backslash.. but that only works if i put double backslashes in the path.

Hope you can help me!
 
Share this answer
 
Comments
André Kraak 10-Oct-11 2:38am    
If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution.
Thank you.
epanjohura 10-Oct-11 2:41am    
Doesn't matter, I was the person who's written this question, so I will get all E-mail messages. But I'm not going to do something like this again. I'm sorry :S

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900