返回首页
您还没有登录!   登录 | 免费注册 | 搜索 |
中国茶铺
  文章
用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.   


2007-07-17 16:25:01 |  浏览 (2398) |  分类:JAVA ME |  收藏 |