5

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.

Community
  • 1
  • 1
wulfgarpro
  • 6,453
  • 12
  • 67
  • 105

2 Answers2

4

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

Christian Semrau
  • 8,598
  • 2
  • 31
  • 37
  • which makes sense... backslashes are, after all, a quite windows "centric" thing - forward slashes appear more often, I think (and you can actually simply replace backslashes with slashes) – Tedil Aug 14 '11 at 11:08
1
String path = "C:\\myfile.txt";
// or "C:/myfile.txt";
// or "C:" + System.getProperty("file.separator") + "myfile.txt";
Eng.Fouad
  • 111,301
  • 67
  • 311
  • 403