3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Androidでファイル名の拡張子を取得する

Posted at

たまに拡張子ほしい時がある。

/**
* ファイル名から拡張子を取得する
* 単純に一番最後の.以降を取得しているだけ。
* @param fileName ファイル名
* @return ファイルの拡張子。拡張子がない場合はnull
*/
public static String getSuffix(String fileName) {
	if (fileName == null) return null;
	int point = fileName.lastIndexOf(".");
	if (point != -1) {
		return fileName.substring(point + 1);
	} 
	return null;
}
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?