IllegalArgumentException ...在url异常中没有':'

0 java java-me

尝试执行此代码片段时,在url异常中没有':'获取该异常...

FileConnection conn;

try{
    conn =(FileConnection)Connector.open("/NewFile.xml");
    if(!conn.exists())
       conn.create();
    _screen.add(new RichTextField("Connection Established..."));
    _screen.add(new SeparatorField());

} catch(IOException ioe) {
       _screen.add(new RichTextField(ioe.getMessage()));
}
Run Code Online (Sandbox Code Playgroud)

其中/NewFile.xml是我的Project中的xml文件

Mar*_*erg 5

你必须写出像这样的路径

文件:///NewFile.xml/

try{ 
conn =(FileConnection)Connector.open("file:///NewFile.xml/"); 
if(!conn.exists()) 
  conn.create(); 
_screen.add(new RichTextField("Connection Established...")); 
_screen.add(new SeparatorField());

}
catch(IOException ioe)
{
     _screen.add(new RichTextField(ioe.getMessage()));
}
Run Code Online (Sandbox Code Playgroud)

文件连接入门