Java URI类文件位置

Java URI类文件位置,java,eclipse,uri,workspace,home-directory,Java,Eclipse,Uri,Workspace,Home Directory,为什么这段java代码在我的主目录中查找文件?为什么它不在我的eclipse工作区(/home/user/eclipse/workspace/)中 它不应该在工作区目录中查找文件。它应该在当前工作目录的父目录中查找文件(因为路径以。)开头)。从eclipse运行时的当前工作目录是项目的目录 我猜你的项目在你的主目录下,所以这就是原因。事实上是这样。在基于Unix的shell中,“…”表示当前工作目录之上的目录。因此,它实际上是在Eclipse程序周围的文件夹中查找,或者查找正在运行的任何东西 H

为什么这段java代码在我的主目录中查找文件?为什么它不在我的eclipse工作区(/home/user/eclipse/workspace/)中


它不应该在工作区目录中查找文件。它应该在当前工作目录的父目录中查找文件(因为路径以
)开头)。从eclipse运行时的当前工作目录是项目的目录


我猜你的项目在你的主目录下,所以这就是原因。

事实上是这样。在基于Unix的shell中,“…”表示当前工作目录之上的目录。因此,它实际上是在Eclipse程序周围的文件夹中查找,或者查找正在运行的任何东西

Home将由“//Home”表示

当前工作目录由“”的值表示

用户的目录由“~”表示

最后,根由“/”表示

例如:

Macintosh-2:/ Administration$ cd ~ #!sends me from root to my user directory
Macintosh-2:~ Administration$ cd ../Administration #!sends me from my user directory, to the directory above it, then back down 
Macintosh-2:~ Administration$ cd Administration #!user directory doesn't exist inside my user directory, thus showing ".." represents the directory above the current working one.
-bash: cd: Administration: No such file or directory
Macintosh-2:~ Administration$ cd .. #!moves up a directory
Macintosh-2:Users Administration$ #!now working in surrounding directory.
获取资源

资源getResource(URI、boolean loadOnDemand)

为了将给定的URI解析为资源,资源集需要实现以下策略。首先,它使用它的URI转换器来规范化URI,然后将其与每个资源的规范化URI进行比较;如果找到匹配项,则该资源将成为结果。如果做不到这一点,它将委托允许在其他地方解析URI。例如,包注册表用于将包的命名空间URI解析为该包的静态实例。因此,重要的一点是,任意实现可以将URI解析为任何资源,而不一定解析为该特定资源集包含的资源。如果委派步骤未能提供结果,并且loadOnDemand为true,则将创建一个资源,该资源将成为结果。如果loadOnDemand为true且结果资源未加载,则将在返回之前加载它

Parameters:
    uri - the URI to resolve.
    loadOnDemand - whether to create and load the resource, if it doesn't 
    already exists. 
Returns:
    the resource resolved by the URI, or null if there isn't one and it's not 
    being demand loaded. 
Throws:
    java.lang.RuntimeException - if a resource can't be demand created. 
    WrappedException - if a problem occurs during demand load.

因此,找不到资源,并在您的主目录中创建任意资源。

但我的项目位于“/home/medy75/Eclipse/dev_workspace/cz.cvut.visualization”中,前面的路径(“../models/task.cm”)从“/home/medy/”中获取文件。所以我不明白…@medy75:这是一个RCP/插件应用程序吗?如果是这样的话,你的临时工作区是在哪里创建的(rcp_workspace或其他)?是的,应该是Eclipse插件,关于临时工作区我完全不知道…@medy:查看你的主目录。。。是否有包含“rcp”、“工作区”、“eclipse”等字样的文件夹?您应该能够通过在eclipse中打开运行配置来识别此文件夹。啊,我想它在我的“/home/medy75/eclipse/runtime-New_配置”中。是的,我知道,但这段代码不尊重它。“home/medy75/models”不在“/home/medy75/Eclipse/dev_workspace/cz.cvut…”的上方。
Returns the resource resolved by the URI.
Parameters:
    uri - the URI to resolve.
    loadOnDemand - whether to create and load the resource, if it doesn't 
    already exists. 
Returns:
    the resource resolved by the URI, or null if there isn't one and it's not 
    being demand loaded. 
Throws:
    java.lang.RuntimeException - if a resource can't be demand created. 
    WrappedException - if a problem occurs during demand load.