饒榮慶 -- 您今天UCWEB了嗎?--http://www.ucweb.com

          3G 手機開發網

             :: 首頁 :: 聯系 :: 聚合  :: 管理
            99 Posts :: 1 Stories :: 219 Comments :: 0 Trackbacks
          關鍵字: J2ME   JSR 75, j2me    

          終于足球項目告一段落,期間學辛苦,無奈與成長都是可寫的。
          在此期間我讓UI折騰的緊,甚至曾經想放棄,終究是堅持下來了。想想在一個小小的屏幕上設計一個UI已經是很痛苦的已經事情,何況在pc上設計,真是佩服死了那些高手們。
          最近,時間比較有空,所以把UI修改了下,然后在此基礎上+jsr75規范做了個電子書閱讀軟件。等我設計好了以后,打算開源,大家共同學習,雖然寫的不好,各位高手多指教。現在發布一些讀取手機目錄的方法。

          代碼
          1. package org.pook.file;  
          2.   
          3. import java.io.IOException;  
          4. import java.util.Enumeration;  
          5. import java.util.Vector;  
          6.   
          7. import javax.microedition.io.Connector;  
          8. import javax.microedition.io.file.FileConnection;  
          9. import javax.microedition.io.file.FileSystemRegistry;  
          10.   
          11. import org.pook.log.Log;  
          12.   
          13. /**  
          14.  * <b>類名:BookFileImpl.java</b> </br>   
          15.  * 編寫日期: 2006-10-12 <br/>  
          16.  * 程序功能描述: <br/>  
          17.  * Demo: <br/>  
          18.  * Bug: <br/>  
          19.  *   
          20.  * 程序變更日期 :<br/>   
          21.  * 變更作者 :<br/>   
          22.  * 變更說明 :<br/>  
          23.  *   
          24.  * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>  
          25.  */  
          26. public class BookFileImpl implements BookFile {  
          27.     private static Log log = Log.getLog("BookFileImpl");  
          28.       
          29.     FileConnection conn = null;  
          30.       
          31.     BookFileImpl(String url){  
          32.         try {  
          33.             conn = (FileConnection) Connector.open( url, Connector.READ);  
          34.   
          35.              
          36.         }catch( IOException e ){  
          37.             e.printStackTrace();  
          38.         }  
          39.         catch( SecurityException e ){  
          40.            e.printStackTrace();  
          41.         }  
          42.   
          43.     }  
          44.       
          45.       
          46.     public Vector listName() throws IOException {  
          47.            
          48.         Vector vc = null;  
          49.          if( conn.isDirectory() ){  
          50.                 Enumeration names = conn.list();  
          51.                 vc = new Vector();       
          52.                 while( names.hasMoreElements() ){  
          53.                     vc.addElement(names.nextElement());  
          54.                       
          55.                 }  
          56.                 return vc;  
          57.             } else {  
          58.                 return null;  
          59.           }  
          60.     }  
          61.   
          62.     public String read() throws IOException {  
          63.           return null;  
          64.     }  
          65.   
          66.     public boolean isFile() {  
          67.           
          68.         if(conn.isDirectory())  
          69.             return false;  
          70.         else  
          71.             return true;  
          72.     }  
          73.   
          74.     public String getFilePath() {  
          75.         checkConn();  
          76.         return conn.getPath();  
          77.     }  
          78.   
          79.     private void checkConn() {  
          80.         if(conn == null)  
          81.             throw new NullPointerException("文件資源不存在!");  
          82.           
          83.     }  
          84.   
          85.     public String getFileName() {  
          86.         checkConn();  
          87.         return conn.getName();  
          88.     }  
          89.   
          90.     public void close() {  
          91.         if(conn != null)  
          92.             try {  
          93.                 conn.close();  
          94.             } catch (IOException e) {  
          95.                 // TODO 自動生成 catch 塊  
          96.                 e.printStackTrace();  
          97.             }  
          98.           
          99.     }  
          100.   
          101.    
          代碼
          1. package org.pook.file;  
          2.   
          3. import java.util.Enumeration;  
          4. import java.util.Vector;  
          5.   
          6. import javax.microedition.io.file.FileSystemRegistry;  
          7.   
          8. import org.pook.log.Log;  
          9.   
          10. /**  
          11.  * <b>類名:BookFileManager.java</b> </br> 編寫日期: 2006-10-12 <br/> 程序功能描述: <br/>  
          12.  * Demo: <br/> Bug: <br/>  
          13.  *   
          14.  * 程序變更日期 :<br/> 變更作者 :<br/> 變更說明 :<br/>  
          15.  *   
          16.  * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>  
          17.  */  
          18. public class BookFileManager {  
          19.     private static Log log = Log.getLog("BookFileManager");  
          20.     public static boolean available() {  
          21.         String version = System  
          22.                 .getProperty("microedition.io.file.FileConnection.version");  
          23.   
          24.         if (version != null) {  
          25.             return true;  
          26.         } else {  
          27.             return false;  
          28.         }  
          29.   
          30.     }  
          31.   
          32.     public static BookFile openBookFile(String url) {  
          33.         return new BookFileImpl(url);  
          34.     }  
          35.       
          36.       
          37.        
          38.   
          39.     public static Vector listRoots() {  
          40.   
          41.        
          42.         Vector vc = null;  
          43.   
          44.         Enumeration names = FileSystemRegistry.listRoots();  
          45.            
          46.         vc = new Vector();  
          47.   
          48.         while (names.hasMoreElements()) {         
          49.             vc.addElement(names.nextElement());  
          50.             //log.debug(names.nextElement());  
          51.         }  
          52.            
          53.         return vc;  
          54.   
          55.     }  
          56.   




          爬蟲工作室 -- 專業的手機軟件開發工作室
          3G視線 -- 專注手機軟件開發
          posted on 2007-05-08 09:10 3G工作室 閱讀(2903) 評論(5)  編輯  收藏 所屬分類: j2me

          Feedback

          # re: 用j2me設計一個手機電子書閱讀軟件 部分源代碼解釋 2007-05-08 09:42 交口稱贊
          支持,最好能解決證書問題,現在用的是moto-txt,老提示確定,煩死了  回復  更多評論
            

          # re: 用j2me設計一個手機電子書閱讀軟件 部分源代碼解釋 2007-05-08 11:42 爬蟲工作室
          證書的問題,估計程序是不能解決的,得跟廠商談判  回復  更多評論
            

          # re: 用j2me設計一個手機電子書閱讀軟件 部分源代碼解釋 2007-05-08 14:26 交口稱贊
          好像是可以用別人的證書

          之前看過幾篇文章,記不大清除了。。。。。  回復  更多評論
            

          # re: 用j2me設計一個手機電子書閱讀軟件 部分源代碼解釋 2007-05-08 16:47 dreamstone
          這個是我一只想做,但沒時間做的事情,支持一下,希望早日能看到結果。。
          加油吧。  回復  更多評論
            

          # re: 用j2me設計一個手機電子書閱讀軟件 部分源代碼解釋 2007-08-23 15:02 yr
          FileConnection f = (FileConnection)Connector.open("c:/");
          執行這一句會引發IOException,請問哪里錯了.其中"c:/"是通過listRoots()獲得的.  回復  更多評論
            

          主站蜘蛛池模板: 丰顺县| 同德县| 望谟县| 宣城市| 三原县| 白水县| 伊金霍洛旗| 元谋县| 汉中市| 赫章县| 黄冈市| 淮安市| 额济纳旗| 柯坪县| 远安县| 桐庐县| 资阳市| 新余市| 兰州市| 措勤县| 苏尼特左旗| 旅游| 宁明县| 建昌县| 普安县| 敖汉旗| 锦屏县| 富宁县| 吉林市| 桦南县| 洛阳市| 三亚市| 青神县| 旬邑县| 乌兰县| 宾阳县| 揭东县| 项城市| 公主岭市| 溧水县| 龙陵县|