Home >Java >javaTutorial >How to determine whether a file is an image in java

How to determine whether a file is an image in java

王林
王林Original
2020-05-18 14:59:492878browse

How to determine whether a file is an image in java

Can be judged by using the substring() and equals() methods.

The substring() method returns the substring of a string.

The equals() method is used to determine whether the Number object and the method parameters are equal.

(Recommended video tutorial: java video)

Specific code:

String extension = "";
int i = fileName.lastIndexOf('.');
if (i > 0) {
    extension = fileName.substring(i+1);
}
//...
if("jpg".equals(extension)){
    //your code
}

Recommended tutorial: Getting started with java development

The above is the detailed content of How to determine whether a file is an image in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn