判斷文件名後綴名

判斷文件名後綴名,能夠用String  類的方法endsWith("後綴") it

例如: 方法

  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

相關文章
相關標籤/搜索