Home  >  Article  >  Java  >  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-15 09:48:564606browse

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
}

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!

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