Java怎么设置文件类型
发布网友
发布时间:2022-05-22 15:55
我来回答
共2个回答
热心网友
时间:2023-08-18 19:55
这个是选择文件的时候默认的,不能自己设置的。
热心网友
时间:2023-08-18 19:55
String postfix = "";
postfix = filepath.substring(filepath.lastIndexOf("."), filepath.length());
postfix = postfix.toUpperCase();
String contentType = "";
if (postfix.equals(".XLS") || postfix.equals(".XLT") || postfix.equals(".XLW") || postfix.equals(".CSV")) {
contentType = "application/vnd.ms-excel";
} else if (postfix.equals(".DOC")) {
contentType = "application/msword";
} else if (postfix.equals(".RTF")) {
contentType = "application/rtf";
} else if (postfix.equals(".TEXT")) {
contentType = "text/plain";
} else if (postfix.equals(".XML") || postfix.equals(".TXT")) {
contentType = "";
} else if (postfix.equals(".BMP")) {
contentType = "image/bmp";
} else if (postfix.equals(".JPG") || postfix.equals(".JPEG")) {
contentType = "image/jpeg";
} else if (postfix.equals(".GIF")) {
contentType = "image/gif";
} else if (postfix.equals(".AVI")) {
contentType = "video/x-msvideo";
} else if (postfix.equals(".MP3")) {
contentType = "audio/mpeg";
} else if (postfix.equals(".MPA") || postfix.equals(".MPE") || postfix.equals(".MPEG") || postfix.equals(".MPG")) {
contentType = "video/mpeg";
} else if (postfix.equals(".PPT") || postfix.equals(".PPS")) {
contentType = "application/vnd.ms-powerpoint";
} else if (postfix.equals(".PDF")) {
contentType = "application/pdf";
} else if (postfix.equals(".ZIP") || postfix.equals(".RAR")) {
contentType = "application/zip";
}