隨筆 - 64  文章 - 9  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(6)

          我參與的團(tuán)隊(duì)

          隨筆分類(88)

          隨筆檔案(92)

          文章分類(142)

          文章檔案(182)

          天基成員

          學(xué)習(xí)園

          我的海角

          搜索

          •  

          積分與排名

          • 積分 - 183507
          • 排名 - 319

          最新評(píng)論

          1. package lab.sodino.img;  
          2. import java.io.IOException;  
          3. import java.io.InputStream;  
          4. import javax.microedition.io.Connector;  
          5. import javax.microedition.io.file.FileConnection;  
          6. import javax.microedition.midlet.MIDlet;  
          7. import javax.microedition.midlet.MIDletStateChangeException;  
          8. /** @author sodino */  
          9. public class ImgType extends MIDlet {  
          10.     public ImgType() {  
          11.     }  
          12.     protected void destroyApp(boolean arg0) throws MIDletStateChangeException {  
          13.     }  
          14.     protected void pauseApp() {  
          15.     }  
          16.     protected void startApp() throws MIDletStateChangeException {  
          17.         String prefix = "file:///root1/";  
          18.         // testFile(prefix + "logo_cn.gif");  
          19.         // testFile(prefix + "04.jpg");  
          20.         testFile(prefix + "img.png");  
          21.     }  
          22.     public void testFile(String url) {  
          23.         try {  
          24.             int length = 10;  
          25.             FileConnection fc = (FileConnection) Connector.open(url);  
          26.             InputStream is = fc.openInputStream();  
          27.             byte[] data = new byte[length];  
          28.             is.read(data);  
          29.             String type = getType(data);  
          30.             System.out.println(url + " is " + type);  
          31.             is.close();  
          32.             fc.close();  
          33.         } catch (IOException e) {  
          34.             e.printStackTrace();  
          35.         }  
          36.     }  
          37.     public String getType(byte[] data) {  
          38.         String type = null;  
          39.         // Png test:  
          40.         if (data[1] == 'P' && data[2] == 'N' && data[3] == 'G') {  
          41.             type = "PNG";  
          42.             return type;  
          43.         }  
          44.         // Gif test:  
          45.         if (data[0] == 'G' && data[1] == 'I' && data[2] == 'F') {  
          46.             type = "GIF";  
          47.             return type;  
          48.         }  
          49.         // JPG test:  
          50.         if (data[6] == 'J' && data[7] == 'F' && data[8] == 'I'  
          51.                 && data[9] == 'F') {  
          52.             type = "JPG";  
          53.             return type;  
          54.         }  
          55.         return type;  
          56.     }  
          57. }  
          posted on 2010-03-19 23:11 鵬凌 閱讀(1879) 評(píng)論(0)  編輯  收藏 所屬分類: Java --j2ee
          主站蜘蛛池模板: 洪洞县| 五指山市| 遂川县| 施秉县| 江达县| 鄱阳县| 秦皇岛市| 威海市| 赤水市| 丰台区| 阳泉市| 惠来县| 武山县| 昌平区| 孟村| 临漳县| 昌黎县| 怀仁县| 沁源县| 阿坝| 板桥市| 班戈县| 吴川市| 泉州市| 交城县| 海南省| 鄢陵县| 丰宁| 靖安县| 赞皇县| 荣成市| 贵定县| 阳原县| 华容县| 吉木乃县| 睢宁县| 什邡市| 玛纳斯县| 建湖县| 舒城县| 通山县|