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-15 09:48:56
Original
4823 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:
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template