当前位置:编程学习 > JAVA >>

java怎么split路径文件名?

D:\Program Files\apache-tomcat-6.0.37-windows-x86\apache-tomcat-6.0.37\webapps\RecruitmentSolution\upload\recruitmentAgency.txt
我想在recruitmentAgency.txt 前面加个数字或者在recruitmentAgency加个数字?该怎么split呢??求助啊

最后的效果是
D:\Program Files\apache-tomcat-6.0.37-windows-x86\apache-tomcat-6.0.37\webapps\RecruitmentSolution\upload\1_recruitmentAgency.txt
或者是D:\Program Files\apache-tomcat-6.0.37-windows-x86\apache-tomcat-6.0.37\webapps\RecruitmentSolution\upload\1_recruitmentAgency_1.txt
--------------------编程问答--------------------
    	String str ="D:\\Program Files\\apache-tomcat-6.0.37-windows-x86\\apache-tomcat-6.0.37\\webapps\\RecruitmentSolution\\upload\\recruitmentAgency.txt"; 
     String[] s = str.split("\\\\");
--------------------编程问答-------------------- 如果你非要用split做的话:


String fileName = "";
String str ="D:\\Program Files\\apache-tomcat-6.0.37-windows-x86\\apache-tomcat-6.0.37\\webapps\\RecruitmentSolution\\upload\\recruitmentAgency.txt"; 
        String[] s = str.split("\\\\");
       s[s.length - 1] = "1_"+s[s.length - 1]; //"1_"+s[s.length - 1] + "_1"
       for (String string : s) {
       fileName += (string + "\\");
       }
       fileName = fileName.substring(0, fileName.length() - 1);
       System.out.println(fileName);

--------------------编程问答--------------------

String str="D:\\Program Files\\apache-tomcat-6.0.37-windows-x86\\apache-tomcat-6.0.37\\webapps\\RecruitmentSolution\\upload\\recruitmentAgency.txt";
//     str = str.replaceAll("(?=recruitmentAgency.txt)", "1_");//加前面
     str = str.replaceAll("(?<=recruitmentAgency.txt)", "_1");//加后面
     System.out.println(str);
补充:Java ,  Java相关
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,