java中用反斜杠替换正斜杠

时间:2022-12-02 14:44:35

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