關鍵字: J2ME
JSR 75, j2me
終于足球項目告一段落,期間學辛苦,無奈與成長都是可寫的。
在此期間我讓UI折騰的緊,甚至曾經想放棄,終究是堅持下來了。想想在一個小小的屏幕上設計一個UI已經是很痛苦的已經事情,何況在pc上設計,真是佩服死了那些高手們。
最近,時間比較有空,所以把UI修改了下,然后在此基礎上+jsr75規范做了個電子書閱讀軟件。等我設計好了以后,打算開源,大家共同學習,雖然寫的不好,各位高手多指教。現在發布一些讀取手機目錄的方法。
代碼
- package org.pook.file;
- import java.io.IOException;
- import java.util.Enumeration;
- import java.util.Vector;
- import javax.microedition.io.Connector;
- import javax.microedition.io.file.FileConnection;
- import javax.microedition.io.file.FileSystemRegistry;
- import org.pook.log.Log;
- /**
- * <b>類名:BookFileImpl.java</b> </br>
- * 編寫日期: 2006-10-12 <br/>
- * 程序功能描述: <br/>
- * Demo: <br/>
- * Bug: <br/>
- *
- * 程序變更日期 :<br/>
- * 變更作者 :<br/>
- * 變更說明 :<br/>
- *
- * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
- */
- public class BookFileImpl implements BookFile {
- private static Log log = Log.getLog("BookFileImpl");
- FileConnection conn = null;
- BookFileImpl(String url){
- try {
- conn = (FileConnection) Connector.open( url, Connector.READ);
- }catch( IOException e ){
- e.printStackTrace();
- }
- catch( SecurityException e ){
- e.printStackTrace();
- }
- }
- public Vector listName() throws IOException {
- Vector vc = null;
- if( conn.isDirectory() ){
- Enumeration names = conn.list();
- vc = new Vector();
- while( names.hasMoreElements() ){
- vc.addElement(names.nextElement());
- }
- return vc;
- } else {
- return null;
- }
- }
- public String read() throws IOException {
- return null;
- }
- public boolean isFile() {
- if(conn.isDirectory())
- return false;
- else
- return true;
- }
- public String getFilePath() {
- checkConn();
- return conn.getPath();
- }
- private void checkConn() {
- if(conn == null)
- throw new NullPointerException("文件資源不存在!");
- }
- public String getFileName() {
- checkConn();
- return conn.getName();
- }
- public void close() {
- if(conn != null)
- try {
- conn.close();
- } catch (IOException e) {
- // TODO 自動生成 catch 塊
- e.printStackTrace();
- }
- }
代碼
- package org.pook.file;
- import java.util.Enumeration;
- import java.util.Vector;
- import javax.microedition.io.file.FileSystemRegistry;
- import org.pook.log.Log;
- /**
- * <b>類名:BookFileManager.java</b> </br> 編寫日期: 2006-10-12 <br/> 程序功能描述: <br/>
- * Demo: <br/> Bug: <br/>
- *
- * 程序變更日期 :<br/> 變更作者 :<br/> 變更說明 :<br/>
- *
- * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
- */
- public class BookFileManager {
- private static Log log = Log.getLog("BookFileManager");
- public static boolean available() {
- String version = System
- .getProperty("microedition.io.file.FileConnection.version");
- if (version != null) {
- return true;
- } else {
- return false;
- }
- }
- public static BookFile openBookFile(String url) {
- return new BookFileImpl(url);
- }
- public static Vector listRoots() {
- Vector vc = null;
- Enumeration names = FileSystemRegistry.listRoots();
- vc = new Vector();
- while (names.hasMoreElements()) {
- vc.addElement(names.nextElement());
- //log.debug(names.nextElement());
- }
- return vc;
- }
- }