Java獲取路徑中的文件名(正則表達式)


Java獲取路徑中的文件名(正則表達式)

目標

在這個路徑中我想得到model2

/E:/2017-02-21--SoftWare/github/test/Java/poiDemo_word2excel/target/test-classes/model2.docx

 

操作

String srcFile="/E:/2017-02-21--SoftWare/github/test/Java/poiDemo_word2excel/target/test-classes/model2.docx";

String temp[]=srcFile.split("\\/");

此時temp數組為:

E:
2017-02-21--SoftWare
github
test
Java
poiDemo_word2excel
target
test-classes
model2.docx

然后我們

String temp1=temp[temp.length-1];

此時temp1=“model2.docx”

然后我們在按照.點號spilt

String temp3[]=temp1.split("\\.");

String txtFileName=temp3[0];

那么現在txtFileName就為model2

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM