FC api是JSR 75, PDA Optional Packages for the J2ME Platform的一部分,用于访问本地文件系统。
FC api通过Generic Connection Framework(GCF)访问文件系统,允许访问包括存储卡在内的文件系统。
包括如下两个接口和三个类:
FileConnection 访问文件和文件夹的接口。
FileSystemListener 添加删除根目录文件系统的状态监听的接口。
FileSystemRegistry 添加删除根目录文件系统的接口注册类。
ConnectionClosedException 当一个文件句柄的操作被调用,而文件已经被关闭时抛出的异常。
IllegalModeException 当操作所对应的模式不被文件打开模式支持时抛出的异常。
判断是否支持FC: 引用文字
if(System.getProperty("microedition.io.file.FileConnection.version") != null){ // file.separator
// FCOP available
} else {
// FCOP not available
}
打开文件:// CFCard/:
FileConnection fc = (FileConnection) Connector.open("file:///CFCard/");
// SDCard/:
FileConnection fc = (FileConnection) Connector.open("file:///SDCard/");
// MemoryStick/:
FileConnection fc = (FileConnection) Connector.open("file:///MemoryStick/");
// C:/:
FileConnection fc = (FileConnection) Connector.open("file:///C:/");
// / File:
Connection fc = (FileConnection) Connector.open(file:////);
只读方式打开一个文件: String url = "file:///data.txt";
InputConnection conn = null;
int mode = Connector.READ_ONLY;
try {
conn =(InputConnection) Connector.open( url, mode );
// Always check whether the file or directory exists.
// Create the file if it doesn't exist.
if(!conn.exists()) {
}
} catch( IOException ioe ){
// no file
}
创建一个文件:
String url = "file:///SDCard/data.txt";
FileConnection conn = null;
int mode = Connector.WRITE_ONLY;
try {
conn = (FileConnection)Connector.open(url, mode);
if(filecon.create()){ // create the file
OutputStream out = conn.openOutputStream();
// now write data to the file
}
conn.close();
} catch(IOException e){
// error
} catch(SecurityException e){
// no permission to create/write
}
列举一个目录下的文件:// FileConnection.list(String filter, boolean includeHidden)
String url = "file:///C:/";
FileConnection conn = null;
try {
conn = (FileConnection) Connector.open(url);
if( conn.isDirectory() ) {
Enumeration names = conn.list();
while( names.hasMoreElements() ){
String name = (String) e.nextElement();
// do something
}
} else {
// not a directory!
}
} catch(IOException e) {
// could not access the URL
} catch(SecurityException e) {
// no permission to read the directory
}
读取文件内容:String url = "file:///CFCard/data.txt";
InputConnection conn = null;
int mode = Connector.READ_ONLY;
try {
FileConnection fc = (FileConnection)Connector.open(url, mode);
if(!fc.exists()) {
throw new IOException("File does not exist");
}
InputStream is = fc.openInputStream();
byte b[] = new byte[1024];
int length = is.read(b, 0, 1024);
System.out.println("Content of "+fileName + ": "+ new String(b, 0, length));
} catch (Exception e) {
}
分享到:
相关推荐
随着智能化手机的流行,在手机程序中访问文件系统也会越来越频繁。JSR-75的FCAPI可选包为java程序提供了访问文件系统的能力。文章介绍了FCAPI,给出了使用FCAPI的最重要的接口FileConnection时需要注意的事项,分析了...
手机系统目录管理,查看手机上的文件目录结构。java j2me
NULL 博文链接:https://wayfarer.iteye.com/blog/568475
在程序中用fileConnection对手机本地文件进行操作。主要操作的是TXT文件和Image文件。在s60第5版操作平台上通行无障碍。
FileConnection in J2ME
J2ME文件系统的运用,分三部分讲解,含有代码及文件系统的原理,适合初学者使用。
此类可以测试出您所使用的环境的根目录,并且在本地电脑测试时的文件路径,并有读取文件的方法使用跟输出文件流
j2me fileconnection api 本文档讲述了FileConnection API [JSR-075],并简要介绍了该包中包含的MIDlet范例以及诺基亚特有的一些实现细节。
本文档讲述了FileConnection API [JSR-075],并简要介绍了该包中包含的MIDlet范例以及诺基亚特有的一些实现细节。本文档假定读者熟悉Java™编程,并具有移动信息设备描述 (Mobile Information Device Profile, MIDP...
nokia jsr75 imageview src源代码
还原的时候只需通过FileConnection 读取备份的文件,还原到手机通讯录就ok了 主要代码如下 FileConnection fc; String s=""; try { String elem = null; Enumeration e = FileSystemRegistry.listRoots(); ...
Vedio player in j2me. Also may need FileConnection API. @thour: prithwi
J2ME API 速查手册 本手册包含如下内容 ...PDA FileConnection (JSR 75) J2ME Web Services RPC (JSR 172) Scalable 2D Vector Graphics API (JSR-226) SIP API (JSR 180) Wireless Messaging API 1.0 (JSR 120)
PDA FileConnection (JSR 75) J2ME Web Services RPC (JSR 172) Scalable 2D Vector Graphics API (JSR-226) SIP API (JSR 180) Wireless Messaging API 1.0 (JSR 120) WTK2.2 相关文档 Nokia UI API 1.1
PDA FileConnection (JSR 75) J2ME Web Services RPC (JSR 172) Scalable 2D Vector Graphics API (JSR-226) SIP API (JSR 180) Wireless Messaging API 1.0 (JSR 120) WTK2.2 相关文档 Nokia UI API 1.1
PDA FileConnection (JSR 75) J2ME Web Services RPC (JSR 172) Scalable 2D Vector Graphics API (JSR-226) SIP API (JSR 180) Wireless Messaging API 1.0 (JSR 120) WTK2.2 相关文档 Nokia UI API 1.1
1.读取XML格式的数据文件 2.增加读取和保存进度功能
这个jar包是关于j2me中文件的操作的。
PDA FileConnection (JSR 75) J2ME Web Services RPC (JSR 172) Scalable 2D Vector Graphics API (JSR-226) SIP API (JSR 180) Wireless Messaging API 1.0 (JSR 120) WTK2.2 Ïà¹ØÎĵµ Nokia UI API ...
PDA FileConnection (JSR 75) J2ME Web Services RPC (JSR 172) Scalable 2D Vector Graphics API (JSR-226) SIP API (JSR 180) Wireless Messaging API 1.0 (JSR 120) WTK2.2 相关文档 Nokia UI API ...