Ignore escape sequences in java strings?

In C #, I can write the string "\\myDir\\myFile" as @"\myDir\myFile" . What is equivalent for this @ symbol in Java, if any?

+6
java c #
source share
3 answers

As far as I know, such equivalence does not exist in the definition of the Java language.

+7
source share

The easiest way is to use Unix-style paths in Java. Java will figure out what are the real paths 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

By the way, if this is the root drive, you can skip the drive letter. Java will understand /programs if you are looking for C:\programs

+3
source share

There is no equivalent in Java.

In this particular case, you can use File.separator + "myDir" + File.separator + "myFile"

+1
source share

All Articles