java中用反斜杠替换正斜杠

时间:2022-02-10 04:04:14

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String webPath =  "\\"+"upload"+"\\"+"ddd";
        System.out.println(webPath);
        webPath = webPath.replaceAll("\\\\", "/");
        System.out.println(webPath);
    }

}

运行结果

\upload\ddd

/upload/ddd