文件格式類型轉換
Example:
1. txt-->>text/plain-->>Text File
2. doc-->>application/msword-->>Microsoft Word.
具體實現步驟:
1. 讀取ApacheMime類型,并將其存入Properties,位置Apache_Home\conf\mime.types
其截取部分內容如下:
# This is a comment. I love comments. # This file controls what Internet media types are sent to the client for # given file extension(s). Sending the correct media type to the client # is important so they know how to handle the content of the file. # Extra types can either be added here or by using an AddType directive # in your config files. For more information about Internet media types, # please read RFC 2045, 2046, 2047, 2048, and 2077. The Internet media type # registry is at <http://www.iana.org/assignments/media-types/>. # MIME type Extensions application/activemessage application/andrew-inset ez application/applefile application/atom+xml atom application/atomicmail application/batch-smtp application/msword doc
2. 傳入文件后綴作為key值獲取其對應的MIME type,通過一方法將key,value轉換
public static String getKeyByValue(Hashtable hash,String value){ String key=""; String tempValue=""; Enumeration keys=hash.keys(); while(keys.hasMoreElements()){ key=(String)keys.nextElement(); tempValue=(String)hash.get(key); if(tempValue.indexOf(value)>-1) break; } return key; }
3. 根據mime type轉換為文檔類型(借助Windchill平臺)
QueryResult qr = ContentHelper.service.getDataFormats(); while(qr.hasMoreElements()){ DataFormat f = (DataFormat)qr.nextElement(); if(mimetype.equals(f.getMimeType())) return f.getFormatName(); }