Java IllegalArgumentException。。。否';:';url中的异常

Java IllegalArgumentException。。。否';:';url中的异常,java,java-me,Java,Java Me,no':'在url异常中我在尝试执行此代码片段时遇到异常 FileConnection conn; try{ conn =(FileConnection)Connector.open("/NewFile.xml"); if(!conn.exists()) conn.create(); _screen.add(new RichTextField("Connection Established...")); _screen.add(new Separa

no':'在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()));
}

其中/NewFile.xml是我的项目中的一个xml文件

文件访问URL以“file://”开头。

文件访问URL以“file://”开头。…

您必须像

file:///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()));
}

您必须像这样编写路径

file:///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()));
}

使用文件,然后使用toul()

使用文件,然后使用toul()

您不需要文件连接,但可以使用输入流直接从jar读取数据:

Class.getClass().getResourceAsStream("/NewFile.xml");

您不需要文件连接,但可以使用输入流直接从jar读取数据:

Class.getClass().getResourceAsStream("/NewFile.xml");

将前缀“http://”添加到文件路径或url中

将前缀“http://”添加到文件路径或url中

什么是文件连接和连接器?我想是这样我有个问题-您的文件在哪里?它是包含在JAR中还是您试图从文件系统加载它?什么是FileConnection和Connector?我想是这样的我有个问题-您的文件在哪里?它是否包含在JAR中,或者您正在尝试从文件系统加载它?或者,更方便的方法是,创建一个java.io.file对象,然后调用toUrl()。它省去了你对晦涩难懂的文件URL语法的麻烦。是的,它需要一个绝对URL,而不是相对URL。或者,也许更方便的是,创建一个java.io.file对象,然后调用toUrl()。它省去了你对晦涩难懂的文件URL语法的麻烦。是的,它需要一个绝对URL,而不是相对URL。