文件格式類型轉換

文件格式類型轉換
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();
 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值