【问题标题】:Convert file path to URI object emf.common.util.URI将文件路径转换为 ​​URI 对象 emf.common.util.URI
【发布时间】:2015-02-03 16:33:50
【问题描述】:

我需要一个解决方案来将文件路径转换为 ​​EMF URI,而不是 Java URI。

我试过这个:

org.eclipse.emf.common.util.URI ur = org.eclipse.emf.common.util.URI.createURI(URI.createURI(file.getPath()).toString());

...但我得到了这个例外:

java.net.MalformedURLException: unknown protocol: c appears .

还有其他解决方案吗?

【问题讨论】:

  • emf URI 可以指向文件吗? URI.createURI(file.getPath()) 中的协议是什么?

标签: java eclipse uri filepath emf


【解决方案1】:

在 EMF 中,URI 类带有许多静态方法来帮助您创建 URI。在您的具体情况下,请尝试 URI.createFileURI(...) 而不是 URI.createURI(...)

URI fileURI = URI.createFileURI(file.getAbsolutePath());

查看方法的详细信息:http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.3/org/eclipse/emf/common/util/URI.html#createFileURI(java.lang.String)

【讨论】:

  • 谢谢。我解决了这个问题:Resource resource = resourceSet.createResource(URI.createURI(file.toURI().toString()));
猜你喜欢
  • 2015-02-22
  • 1970-01-01
  • 2011-01-27
  • 2017-08-09
  • 2015-02-20
  • 1970-01-01
  • 1970-01-01
  • 2018-05-28
相关资源
最近更新 更多