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
Java路径中提取文件名
本文介绍了一种使用Java从完整文件路径中提取文件名的方法。通过使用split方法结合正则表达式,可以有效地分离出文件名部分,并进一步去除文件扩展名。
1958

被折叠的 条评论
为什么被折叠?



