之前遇到过 "/", 在 esclipse 中报错, 只认识 "//","\" 符号, 需要将 string 字符串 "/", 转换成 "//" 或者 "\" 怎么转呢?
获取字符串是 String path = "/root/data/image";
- StringBuilder sb = new StringBuilder();
- if (path.contains("\\")) {
- String t = path.replaceAll("\\\\", "/");
- sb.append(t);
- }
- String fromFile = sb.toString();
- System.out.println(fromFile);
这样就可以转换成功了!
来源: http://www.bubuko.com/infodetail-3090012.html