黑马程序员技术交流社区
标题:
如何分割文件名
[打印本页]
作者:
ifuzhen
时间:
2014-4-24 19:17
标题:
如何分割文件名
本帖最后由 ifuzhen 于 2014-4-26 20:38 编辑
比如:文件名D:\Documents\Music\信乐团 - 假如1.mp3;
如何把"1.mp3"和整个文件名分开?
split函数怎么实现?其他函数可以么?
作者:
张耀扬
时间:
2014-4-25 00:19
public class Test0000 {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("D:\\笔记.txt");
System.out.println(file.getName());
//用file类的getname方法,返回文件或文件夹的名字
String [] str="D:\\笔记.txt".split("\\\\");
//可以用split方法,得到最后str数组的最后一个字符串即可
String fileName =str[str.length-1];
System.out.println(fileName);
}
}
作者:
展展
时间:
2014-4-25 11:50
int lastIndexOf(String str)
返回指定子字符串在此字符串中最右边出现处的索引。
用这个方法好像也挺好的,之前我用过了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2