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

          常用鏈接

          留言簿(6)

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

          隨筆分類(lèi)(88)

          隨筆檔案(92)

          文章分類(lèi)(142)

          文章檔案(182)

          天基成員

          學(xué)習(xí)園

          我的海角

          搜索

          •  

          積分與排名

          • 積分 - 183404
          • 排名 - 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)  編輯  收藏 所屬分類(lèi): Java --j2ee
          主站蜘蛛池模板: 万盛区| 太仆寺旗| 罗平县| 甘谷县| 讷河市| 渭源县| 常州市| 澄城县| 运城市| 平舆县| 青海省| 五家渠市| 闽侯县| 辽宁省| 黎城县| 巴林左旗| 绥滨县| 论坛| 台中县| 鲁甸县| 囊谦县| 寻甸| 海南省| 方城县| 阿荣旗| 民勤县| 定南县| 卓尼县| 尤溪县| 和政县| 呼玛县| 江北区| 庐江县| 理塘县| 裕民县| 柳林县| 信丰县| 定结县| 尼勒克县| 崇明县| 来安县|