String类型得路径如换获取到该文件得文件名

如一个String类型类型得路径如下

D:ppt\ppp.qws.ppt
如何获得.ppt得类型
D:img\spoe.tjrt\444.jpg
如何获得.jpg得类型
D:mp4\dertr-gfhhfh\dgdfg.mad.dewq.mp4
如何获得.mp4得类型

    String p1 = "D:ppt\\ppp.qws.ppt";
        String p2 = "D:img\\spoe.tjrt\\444.jpg";
        String p3 = "D:mp4\\dertr-gfhhfh\\dgdfg.mad.dewq.mp4";
        String filename1 = p1.substring(p1.lastIndexOf('\\')+1);
        String suffix1=p1.substring((p1.lastIndexOf('.')));
        System.out.println("p1的文件名:"+filename1+"\tp1的后缀名:"+suffix1);
        String filename2 = p2.substring(p2.lastIndexOf('\\')+1);
        String suffix2=p2.substring((p2.lastIndexOf('.')));
        System.out.println("p2的文件名:"+filename2+"\tp2的后缀名:"+suffix2);
        String suffix3=p3.substring((p3.lastIndexOf('.')));
        String filename3 = p3.substring(p3.lastIndexOf('\\')+1);
        System.out.println("p3的文件名:"+filename3+"\tp3的后缀名:"+suffix3);

运行结果:
图片说明
回答不易,希望能够给个采纳,谢谢!

用substring和lastIndexOf即可实现,如下面demo

        String path="D:ppt\\ppp.qws.ppt";
        String suffixName=path.substring(path.lastIndexOf('.'));

不需要自己处理

import java.io.File;

File file = new File("D:\\ppt\\ppp.qws.ppt");
String s = file.getName();