Java based on file name to judge file type __java, tool class

Source: Internet
Author: User

/* AUTHOR:ZSS
* Date: March 31, 2017
* Function: According to the file name to determine the type
* Accept parameter type: String
* Return parameter type: String
* Note: The file type is not perfect, it is necessary to add
*/
public class FileType {
public string FileType (string fileName) {
if (FileName = = null) {
filename = "file name is empty. ";
return fileName;


} else {
Gets the file suffix name and converts it to write for subsequent comparisons
String FileType = filename.substring (Filename.lastindexof (".") + 1, filename.length ()). toLowerCase ();
Create an array of picture types
String img[] = {"BMP", "JPG", "JPEG", "PNG", "TIFF", "GIF", "PCX", "TGA", "Exif", "FPX", "SVG", "PSD",
"Cdr", "PCD", "DXF", "UFO", "EPS", "AI", "raw", "WMF"};
for (int i = 0; i < img.length; i++) {
if (Img[i].equals (FileType)) {
return "picture";
}
}


Creating an array of document types
String document[] = {"TXT", "Doc", "docx", "xls", "htm", "html", "JSP", "RTF", "WPD", "PDF", "ppt"};
for (int i = 0; i < document.length; i++) {
if (Document[i].equals (FileType)) {
Return "Document";
}
}
Creating an array of video types
String video[] = {"mp4", "avi", "mov", "wmv", "ASF", "Navi", "3GP", "mkv", "F4V", "rmvb", "WEBM"};
for (int i = 0; i < video.length; i++) {
if (Video[i].equals (FileType)) {
return "video";
}
}
Create an array of music types
String music[] = {"MP3", "WMA", "WAV", "mod", "RA", "CD", "MD", "ASF", "AAC", "VQF", "Ape", "mid", "Ogg",
"M4A", "VQF"};
for (int i = 0; i < music.length; i++) {
if (Music[i].equals (FileType)) {
return "Music";
}
}


}
return "other";
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.