在字符串中包含双反斜杠作为纯文本符号
Include Double Backslash as plain text symbols in a String
我有一个纯字符串,其中包含“\”。但是 Java 似乎在看到双反斜杠时试图格式化字符串。有没有办法告诉字符串完全忽略反斜杠格式?
String Test = "File location is: C:\Folder\File.txt";
输出:
Test = "File location is: C:\Folder\File.txt"
期望的输出:
Test = "File location is: C:\Folder\File.txt"
试试这个:
public class Sample {
public static void main(String[] args){
String test = "File location is: C:\\Folder\\File.txt";
System.out.println("Test = "+ test);
}
}
输出:
Test = File location is: C:\Folder\File.txt
我有一个纯字符串,其中包含“\”。但是 Java 似乎在看到双反斜杠时试图格式化字符串。有没有办法告诉字符串完全忽略反斜杠格式?
String Test = "File location is: C:\Folder\File.txt";
输出:
Test = "File location is: C:\Folder\File.txt"
期望的输出:
Test = "File location is: C:\Folder\File.txt"
试试这个:
public class Sample {
public static void main(String[] args){
String test = "File location is: C:\\Folder\\File.txt";
System.out.println("Test = "+ test);
}
}
输出:
Test = File location is: C:\Folder\File.txt