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!