j2me 在诺基亚手机(支持jsr75)里怎么创建文件?

来源:百度知道 编辑:UC知道 时间:2024/06/06 12:06:04

用手机菜单操作也可以,但还是比较麻烦。
直接连接到电脑上,用电脑建省事、快捷。

1.获取文件创建位置
public String getPath() {
StringBuffer path = new StringBuffer();
path.append("file:///");
Enumeration e = FileSystemRegistry.listRoots();
String root = (String) e.nextElement();
while(e.hasMoreElements()) {
root = null;
root = (String) e.nextElement();
}
path.append(root);
path.append("yourFolderName");
return path.toString();
}
2.调用(FileConnection)Connector.open(url)创建文件,具体如下
写文件:
FileConnection fc = (FileConnection)Connector.open(ref);
if(!fc.exists()) {
fc.create();
}
DataOutputStream dos = new DataOutputStream(fc.openDataOutputStream());
如果写整数,则调用dos.writeInt(int)
如果写字符串,则调用dos.writeUTF(String)

读文件:
FileConnection fc = (FileConnection) Connector.open(ref);
if(fc.exists() && fc.canRead()) {
DataInputStream dis = new DataInputStream(fc.openDataInputStr