hhrt456
V2EX  ›  域名

判断文件名后缀名

  •  
  •   hhrt456 · Jan 29, 2016 · 471 views
    This topic created in 3773 days ago, the information mentioned may be changed or developed.

    判断文件名后缀名,可以用 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
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2488 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:48 · PVG 23:48 · LAX 08:48 · JFK 11:48
    ♥ Do have faith in what you're doing.