为什么带有"\"的路径显示为"\\"? [英] Why is path with '\' showed as '\\' ?
本文介绍了为什么带有"\"的路径显示为"\\"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在用Java在Eclipse中对应用程序进行编程,我使用了带有路径(例如C:\ Java \ Test-Application \ config.ini)的输入文件.
当我调试该应用程序时,此路径写为:
C:\\ Java \\ Test-Application \\ config.ini
为什么会这样呢?我不太明白,为什么会有双反斜杠而不是一个.
感谢您的帮助.
Painjofshem
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
推荐答案
该\被视为转义字符,因此您需要\\告诉Java它是\
the \ is seen as an escape character so you need \\ to tell java it is \
是因为\
是转义字符 [
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\
.
''\''是转义字符
因此要将路径中的"\"视为普通字符而不是转义字符,则需要使用"\\".
这就是为什么调试器显示"\\"的原因.
''\'' 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 ''\\''.
这篇关于为什么带有"\"的路径显示为"\\"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文