在C#中,如果要读取字符串而不必转义字符,可以使用at-quote
String file = @"C:\filename.txt"
Run Code Online (Sandbox Code Playgroud)
这相当于
String file = "C:\\filename.txt"
Run Code Online (Sandbox Code Playgroud)
有一种简单的方法可以在Java中转义整个字符串吗?
不,不幸的是没有.
作为旁注:如果您不想再支持Windows 9x和ME,可以使用"/"作为文件夹分隔符.它适用于所有操作系统,包括自2000年以来的Microsoft Windows.