In C#, I can write the string "\\myDir\\myFile"
as @"\myDir\myFile"
. What is the equivalent for this "@" character in Java, if any?
To ignoring escape sequences in the string, we make the string as "raw string" by placing "r" before the string. "raw string" prints as it assigned to the string.
For turning a normal string into a raw string, prefix the string (before the quote) with an r or R. This is the method of choice for overcoming this escape sequence problem.
Java String equalsIgnoreCase() Method The equalsIgnoreCase() method compares two strings, ignoring lower case and upper case differences. This method returns true if the strings are equal, and false if not. Tip: Use the compareToIgnoreCase() method to compare two strings lexicographically, ignoring case differences.
In Java, if a character is preceded by a backslash (\) is known as Java escape sequence or escape characters. It may include letters, numerals, punctuations, etc. Remember that escape characters must be enclosed in quotation marks (""). These are the valid character literals.
To my knowledge no such equivalence exist in the Java language definition.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With