qq_36007493
qq_36007493
2017-12-07 06:04

在JSP或者JAVA中获取的磁盘路径的\替换为\\

  • java

例如:String path = request.getServletContext().getRealPath("/") + "WordDir";
path在控制台输出为F:\workSpace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\cloudedu\WordDir2017120713194146bb0.docx
然后我使用path.replaceAll("\\", "\\\\");
结果并不能得到:
F:\\workSpace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\cloudedu\\WordDir2017120713194146bb0.docx
请大神解答!!!!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答