日期:2014-05-20  浏览次数:20803 次

创建本地文件错误“ Root is not accessible”请高手指教
public void AddPhoto(byte[] snap){
  try{
  FileConnection fc=(FileConnection)Connector.open("file:///root/resources/base");
  if(!fc.exists()){
  fc.create();
  OutputStream out = fc.openOutputStream();
  out.write(snap);
  out.flush();
  out.close();

  }  
  System.out.println("*****addphoto*****");
  fc.close();
  }catch(Exception e){
  System.out.println("*****fc****");
  e.printStackTrace();
  }
为什么这段代码会出现这些错误:
java.io.IOException: Root is not accessible
Generic/DefaultColorPhone: at com.sun.midp.io.j2me.file.Protocol.ensureConnected(+47)
Generic/DefaultColorPhone: at com.sun.midp.io.j2me.file.Protocol.ensureOpenAndConnected(+21)
Generic/DefaultColorPhone: at com.sun.midp.io.j2me.file.Protocol.create(+8)
Generic/DefaultColorPhone: at com.protel.MM.Control.MutiFile.AddPhoto(+24)
Unable to translate stacktrace: Unable to start the "jad"-decompiler: [java.io.IOException: Cannot run program "jad.exe": CreateProcess error=2, The system cannot find the file specified]. jad is available from http://www.kpdus.com/jad.html.
Generic/DefaultColorPhone: at com.protel.MM.View.NoticForm$1.run(+17)


------解决方案--------------------
在我的机器上file:///root1/就对应如下地址
C:\WTK2.5.1\appdb\DefaultColorPhone\filesystem\root1
我的wtk装在c盘,你自己改改吧。
建议先使用如下方法获取根目录列表。
Java code
    public String[] DeviceGetRoots() {
        Enumeration enumRoot = FileSystemRegistry.listRoots();// 返回根目录组成的序列
        Vector list = new Vector();
        while (enumRoot.hasMoreElements()) {
            list.addElement(enumRoot.nextElement());
        }

        String[] ret = null;
        if (list.size() > 0) {
            ret = new String[list.size()];
            for (int i = 0; i < list.size(); i++) {
                ret[i] = (String) list.elementAt(i);
            }
        }
        return ret;
    }

------解决方案--------------------
mark
------解决方案--------------------
根目录写错了吧
wtk上应该是 file://localhosst/root
------解决方案--------------------
我用FileConnection创建目录时也遇到类似的问题,还不知道怎么解决!
------解决方案--------------------
根目录地址错了吧。 [file:///] 或者 [file://localhost/] 表示模拟器的根目录地址。