日期:2014-05-20 浏览次数:21125 次
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;
}
}