Ignore escape sequences in strings java?
In C#, I can write the string "\\myDir\\my开发者_JAVA技巧File"
as @"\myDir\myFile"
. What is the equivalent for this "@" character in Java, if any?
To my knowledge no such equivalence exist in the Java language definition.
The easiest way is to Use Unix-style paths in Java. Java will find out what the real paths are in all File-based code.
System.out.println(new File("c:/dev/m2-repo/org/apache/ant").getCanonicalPath());
Output:
C:\dev\m2-repo\org\apache\ant
BTW if it's the root drive, you can skip the drive letter. Java will understand /programs
if you look for C:\programs
There is no equivalent in Java.
For this concrete case you can use File.separator + "myDir" + File.separator + "myFile"
精彩评论