2007/04/03

判斷檔案的 ContentType/MIME-Type

import javax.activation.MimetypesFileTypeMap;
import java.io.File;

class GetContentType {
public static void main(String args[]) {
File f = new File("gumby.gif");
System.out.println("Mime Type of " + f.getName() + " is " +
new MimetypesFileTypeMap().getContentType(f));
// "Mime Type of gumby.gif is image/gif"
}
}

[註]有可能會mapping不到資料,可以查詢j2ee api : javax.activation.MimetypesFileTypeMap。MIME types

沒有留言:

NGINX SSL/設定檔案

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #...