Every time I use File.separator
in Java code, I get the error because '\\'
is an escape character in Windows and Java doesn't recognise "quotes".
I tried doing this: String[] split = strData.toString().split(File.pathSeparator);
, but it crashes with following error message:
Caused by: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
^
File.pathSeparator = ;
File.separator = \
strData.toString() = C:\Users\server\Desktop\minecraft\plugins\krneki
由于String.split
的参数是一个正则表达式,您需要引用分隔符才能将其视为文字:
String[] split = strData.toString().split(Pattern.quote(File.pathSeparator));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.