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

王林
Release: 2020-05-18 14:59:49
Original
2871 people have browsed it

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
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template