String filePath = this.getClass().getResource("/").getPath(); filePath = filePath.replaceAll("\\/|"+Matcher.quoteReplacement("\\"),Matcher.quoteReplacement(File.separator)); System.out.println("filePath: " + filePath+"html" +File.separator+"56465");
replace File.separator出现异常:【java.lang.IllegalArgumentException: character to be escaped is missing】...
public static void main(String[] args){ String filePath = this.getClass().getResource("/").getPath(); filePath = filePath.replaceAll("\\", File.separator); System.out.println(filePath); }
The reason is that the windows File.separator
as "", will be treated as an escape character processing, a look back after this character, if nothing, they reported anomalies in the title.