Home > Java > javaTutorial > body text

How to determine whether a file is an image in java

王林
Release: 2020-05-15 09:48:56
Original
4548 people have browsed it

How to determine whether a file is an image in java

When uploading image files, we generally limit the size of the uploaded file, but we usually also determine the type of uploaded file.

There are many ways to determine the file type. For example, we can determine whether the file is an image type by judging the file extension.

(Video tutorial recommendation: java video)

Judge by file suffix name

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: java entry program

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!