1. 程式人生 > >檔案上傳獲取檔案的contentType

檔案上傳獲取檔案的contentType

public static String getMimeType(String filePath) throws Exception

{

if(filePath == null && filePath.equals(""))

{

throws new Exception("filePath is null or empty");

}

Path tmpPath = Paths.get(filePath);

String contentType =  Files.probeContentType(tmpPath);

if(contentType == null && contentType.equals(""))

{

contentType = "application/octet-stream";

}

return contentType;

}