6

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,666
  • 12
  • 69
  • 110

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,913
  • 2
  • 32
  • 39
  • 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
  • 115,165
  • 71
  • 313
  • 417