Get the current project path + sign conversion path

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.separatoras "", will be treated as an escape character processing, a look back after this character, if nothing, they reported anomalies in the title.

Guess you like

Origin www.cnblogs.com/weibanggang/p/11897849.html