开发者

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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜