Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java equivalent to C#'s @ symbol for escaping \ [duplicate]

Tags:

java

c#

escaping

Possible Duplicate:
Java equivalent of C#'s verbatim strings with @

An example in C# would be:

string path = @"C:\myfile.txt";

Another example is the answer to this question.

like image 555
wulfgarpro Avatar asked Aug 14 '11 09:08

wulfgarpro


People also ask

What is the equivalent of pointers in Java?

Java doesn't have pointers; Java has references.

Does Java have unions?

Since the Java programming language does not provide the union construct, you might think there's no danger of implementing a discriminated union. It is, however, possible to write code with many of the same disadvantages.

What does the operator do in Java?

Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result. As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest precedence.


2 Answers

There is nothing equivalent to the @ symbol in Java - you must escape each and every backslash in a String literal.

like image 51
Christian Semrau Avatar answered Oct 13 '22 22:10

Christian Semrau


String path = "C:\\myfile.txt";
// or "C:/myfile.txt";
// or "C:" + System.getProperty("file.separator") + "myfile.txt";
like image 34
Eng.Fouad Avatar answered Oct 13 '22 22:10

Eng.Fouad