Home >Java >javaTutorial >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 }
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!