Java equivalent of C#'s verbatim strings with @

No. Escaping / externalizing the string is your only choice.


No, Java doesn't have verbatim string literals.

If you want a Java-like (and Java-VM-based) language that does, however, you might want to look at Groovy which has various forms of string literal.


As Kent and Jon have said, no there isn't.

I'm answering just to point out that even if there were, for your particular case, it would be a bad idea in the general case, assuming a more than one-off program.

Java programs run on more platforms than just Windows, and other platforms have different file delimiters. So instead of dealing with escaped backslashes, the correct way to handle your particular example is by getting the file separator property:


    String sep = System.getProperty("file.separator");
    String filename = ROOTDIR + sep + "folder" + sep + "afile";

Where you'd have separately created ROOTDIR based on some policy - not only the platform, but whether you want your "afile" to be relative to the actual file system root, or relative to the user's home directory.

But definitely, using the file separator property makes your programs more widely usable. Is it more work? Yes. As Wanda Sykes says, "But it's worth it".