JSR75和MOTO FileConnection的真机表现

前段时间接了一个软件外包的项目,是一个J2ME平台上的铃声图片下载和本地资源管理的的小程序.软件的核心就是JSR75、MOTO FileConnection和http连接的使用.在网络方面遇到的问题不大,主要是在使用FC时产生了很多真机上出现的问题.我把它归纳起来有以下几点:

(1)NOKIA机器上使用支持JSR75 FC
在用WTK打包的使用一定要把读写(有需要才加写)操作的permissions加上。如果没有加NOKIA的数字签名的话,在真机上需要把使用询问设置为每次都询问,如果不的话真机上会发生SecurityException的安全异常。而且在NOKIA的机器上C盘下不能创建文件夹。

(2)MOTO机器上使用支持JSR75 FC或MOTO FileConnection
在MOTO较早的机型上,以C650、C380、E398、V303等为代表的机器上面都是实现的MOTO FileConnection而且在使用上没有做任何的安全限制,而在其后的一些机器像E680、V3等一些机器就对使用这组API作出了很多的限制,必须拿到MOTO厂商的签名才能正常的使用。从标准的JSR75和MOTO FileConnection在使用上的区别只有很少的一些,我在移植的过程中遇到的主要是JSR75中FileSystemRegistry.listRoots()和FileConnection.List()返回的都是一个Enmumeration,数据是以String保存在Enmumeration中的,并且返回的是这一级目录。在MOTO FileConnection中FileSystemRegistry.listRoots()和FileConnection.List()返回的直接是String数组,并且是一个完整的目录形式。比如在有这样一个目录结构/a/zk/,里面有1.png和2.png两个文件,如果是JSR75的FileConnection.List()返回的Enmumeration中存储的是1.png和2.png两个String,而使用MOTO FileConnection返回的是/a/zk//1.png和a/zk/2.png存储在String数组中。
注意好以上这些问题了连接本地文件就很简单了。
 

求教:真机测验,FileConnection问题

11-30

现在需要操作手机文件系统,只需在指定目录下创建文件,写入文件和读文件即可,为避免证书之类的问题,因此将jsr75demo包内的FileConnection类摘出来了,放在自己的工程中,在塞班s60第三版的系统下测试,手机为诺基亚,在测试时报下面的异常:rnclass cast java.lang.castexception:com.symbian.midp.io.protocol.file.fileconnectionimpl incompatible with Demo.FileConnenctionrn塞班的FileConnection和工程的FileConnection不一样?应该怎么解决啊?rn代码如下:rn[color=#FF0000]<1>FileConnection :[/color]rnimport java.io.DataInputStream;rnimport java.io.DataOutputStream;rnimport java.io.IOException;rnimport java.io.InputStream;rnimport java.io.OutputStream;rnimport java.util.Enumeration;rnimport javax.microedition.io.StreamConnection;rnrnpublic abstract interface FileConnection extends StreamConnectionrnrn public abstract boolean isOpen();rnrn public abstract InputStream openInputStream()rn throws IOException;rnrn public abstract DataInputStream openDataInputStream()rn throws IOException;rnrn public abstract OutputStream openOutputStream()rn throws IOException;rnrn public abstract DataOutputStream openDataOutputStream()rn throws IOException;rnrn public abstract OutputStream openOutputStream(long paramLong)rn throws IOException;rnrn public abstract long totalSize();rnrn public abstract long availableSize();rnrn public abstract long usedSize();rnrn public abstract long directorySize(boolean paramBoolean)rn throws IOException;rnrn public abstract long fileSize()rn throws IOException;rnrn public abstract boolean canRead();rnrn public abstract boolean canWrite();rnrn public abstract boolean isHidden();rnrn public abstract void setReadable(boolean paramBoolean)rn throws IOException;rnrn public abstract void setWritable(boolean paramBoolean)rn throws IOException;rnrn public abstract void setHidden(boolean paramBoolean)rn throws IOException;rnrn public abstract Enumeration list()rn throws IOException;rnrn public abstract Enumeration list(String paramString, boolean paramBoolean)rn throws IOException;rnrn public abstract void create()rn throws IOException;rnrn public abstract void mkdir()rn throws IOException;rnrn public abstract boolean exists();rnrn public abstract boolean isDirectory();rnrn public abstract void delete()rn throws IOException;rnrn public abstract void rename(String paramString)rn throws IOException;rnrn public abstract void truncate(long paramLong)rn throws IOException;rnrn public abstract void setFileConnection(String paramString)rn throws IOException;rnrn public abstract String getName();rnrn public abstract String getPath();rnrn public abstract String getURL();rnrn public abstract long lastModified();rnrn[color=#FF0000]<2>对文件基本的操作[/color]rnimport java.io.IOException;rnimport java.io.InputStream;rnimport java.io.OutputStream;rnimport javax.microedition.io.Connector;rnimport Demo.FileConnection;rnimport javax.microedition.lcdui.Alert;rnimport javax.microedition.lcdui.AlertType;rnpublic class NewClass rnmainMidlet FileMIDle;rn FileConnection fc=null;rn InputStream inputStream;rnpublic void create(String path)rn tryrn fc=(FileConnection)(Connector.open(path));rn fc.create();rn fc.setWritable(true);rn rn catch(Exception e)rnrnpublic InputStream readFile(String path)rntryrn fc=(FileConnection)(Connector.open(path));rn if(fc.exists())rn inputStream=fc.openInputStream();rn rncatch(Exception e)rne.printStackTrace();rnreturn inputStream;rnrnpublic void Write(String path,String s) throws Exceptionrn fc=(FileConnection)(Connector.open(path));rnOutputStream out=fc.openOutputStream();rn byte[]b=s.getBytes();rn out.write(b, 0, b.length);rn out.close();rn rnrn<3>主类:rnimport java.io.DataInputStream;rnimport javax.microedition.lcdui.*;rnimport javax.microedition.midlet.*;rnrn/**rn * @author Administratorrn */rnpublic class mainMidlet extends MIDlet implements CommandListenerrn public Form mainForm;rn private Display dis;rn String path="file:///e:/1.txt";rn String s="dddddddddddd";rn NewClass nc=new NewClass();rn private Command Connection = new Command("连接",Command.OK,1);rn public void startApp() rn if(dis==null)rn dis=Display.getDisplay(this);rn rn mainForm=new Form("主页面");rn mainForm.addCommand(Connection);rn mainForm.addCommand(Connect);rn mainForm.setCommandListener(this);rn dis.setCurrent(mainForm);rn rn public void pauseApp() rn rn public void destroyApp(boolean unconditional) rn rn public void commandAction(Command c,Displayable d)rn if(d==mainForm)rn if(c==Connection)rn tryrn nc.create(path);rnnc.Write(path,s);rn mainForm.append("成功");rn rn catch(Exception e)rn mainForm.append(e.getMessage().toString());rn System.out.println(e.getMessage().toString());rn e.printStackTrace();rn mainForm.append("失败");rn rn rnrn高手们帮帮忙吧 试了好几个方法 结果都一样

FileConnection

08-11

以下这个程序就是建立一个FileConnection,写一句话rnrn[code=Java]rnimport javax.microedition.io.*;rnimport javax.microedition.lcdui.*;rnimport javax.microedition.midlet.*;rnimport java.io.*;rnrnpublic class FileConnection extends MIDlet implements CommandListenerrn private Command exit,start;rn private Display display;rn private Form form;rn rn public FileConnection() rn display = Display.getDisplay(this);rn exit = new Command("Exit",Command.EXIT,1);rn start = new Command("Start",Command.EXIT,1);rn form = new Form("Write To File");rn form.addCommand(exit);rn form.addCommand(start);rn form.setCommandListener(this);rn rnrn public void startApp() rn display.setCurrent(form); rn rn rn public void pauseApp() rn rnrn public void destroyApp(boolean arg0) rn rn rn public void commandAction(Command command,Displayable displayable) rn if(command == exit) rn destroyApp(false); rn notifyDestroyed(); rn rn else if(command == start)rn tryrn OutputConnection connection = (OutputConnection)Connector.open("file://c:/myfile.txt;append=true",Connector.WRITE);rn OutputStream out = connection.openOutputStream();rn PrintStream output = new PrintStream(out);rn output.println("This is a test");rn out.close();rn connection.close();rn Alert alert = new Alert("Completed","Data written",null,null);rn alert.setTimeout(Alert.FOREVER);rn alert.setType(AlertType.ERROR);rn display.setCurrent(alert);rn catch(ConnectionNotFoundException error)rn Alert alert = new Alert("Error","Cannot access file",null,null);rn alert.setTimeout(Alert.FOREVER);rn alert.setType(AlertType.ERROR);rn display.setCurrent(alert);rn catch(IOException error)rn Alert alert = new Alert("Error",error.toString(),null,null);rn alert.setTimeout(Alert.FOREVER);rn alert.setType(AlertType.ERROR);rn display.setCurrent(alert);rn rn rn rnrn[/code]rnrn报错误:rnjava.lang.IllegalArgumentException: Root is not specifiedrn是不是我的open方法中的参数内容有问题?

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭