/**
* 获取一个文件的类型
* @param path 一个文件路径
* @return
* @throws IOException
*/
public static String getFileType (String path) throws IOException {
File file = new File(path);
if(!file.exists()) {
boolean createNewFile = file.createNewFile();
}
String name = file.getName();
String fileType = name.substring(name.lastIndexOf(".")+1,name.length());
return fileType;
}
/**
*
* @param path 一个文件路径
* @return 获取一个文件的大小
* @throws IOException
*/
public static String getFileSize (String path) throws IOException {
File file = new File(path);
if(!file.exists()) {
boolean createNewFile = file.createNewFile();
}
String filesize = file.length()/1024/1024+"";
return filesize;
}
项目中我已经 过滤出来 是音频 视频和 图片的 localpath 了 再加上这个判断 文件不能大于 20M 和 文件类型做为入参 上传文件。