V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hhrt456
V2EX  ›  域名

判断文件名后缀名

  •  
  •   hhrt456 · 2016-01-29 17:24:43 +08:00 · 192 次点击
    这是一个创建于 3041 天前的主题,其中的信息可能已经有所发展或是发生改变。

    判断文件名后缀名,可以用 String 类的方法 endsWith("后缀")

    例如:

    String str="星辰变.txt";
    String str2="寸芒.mobl";

    if( !str.endsWith(".txt") ){ //判断后缀不是.txt , 输出的格式是 txt

    System.out.println("输出的格式是 txt");
    }
    if(str2.endsWith(".mobl")){ //判断后缀是.mobl , 输出的格式是 mobl

    System.out.println("输出的格式是 mobl");
    }

    控制台输出的结果:

    输出的格式是 mobl
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3455 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:18 · PVG 12:18 · LAX 21:18 · JFK 00:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.