Hari Menon
Hari Menon

Reputation: 35405

Ignore escape sequences in strings java?

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

Upvotes: 6

Views: 2545

Answers (3)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298828

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

Upvotes: 3

rsp
rsp

Reputation: 23373

To my knowledge no such equivalence exist in the Java language definition.

Upvotes: 7

Bozho
Bozho

Reputation: 597036

There is no equivalent in Java.

For this concrete case you can use File.separator + "myDir" + File.separator + "myFile"

Upvotes: 1

Related Questions