将物理地址转换成windows中java可识别的形式:D://Devenv//Server//apache-tomcat-6.0.29//apache-tomcat-6.0.29//webapps//myHand//a.xml
初级结果:
public class Replaces {
public static void main(String[] args) {
String str="D:\\Devenv\\Server\\apache-tomcat-6.0.29\\apache-tomcat-6.0.29\\webapps\\myHand\\a.xml";
String[] str1=str.split("\\\\");
String sbf=str1[0];
for(int i=1;i
sbf=sbf "//" str1[i];
}
System.out.println(sbf);
}
}
最终结果:
public class Replaces {
public static void main(String[] args) {
String str="D:\\Devenv\\Server\\apache-tomcat-6.0.29\\apache-tomcat-6.0.29\\webapps\\myHand\\a.xml";
str=str.replaceAll("\\\\","//");
System.out.println(str);
}
}
由上看得:正则很重要