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