简体   繁体   English

这是相对路径还是绝对路径?

[英]Is this a relative path or an absolute path?

I'm having a little difficulty determining if the path in the code below is a relative path or an absolute path.我很难确定下面代码中的路径是相对路径还是绝对路径。 Also, in this case, I'm trying to open an image I placed inside a folder called "img" which is inside my java project directory.此外,在这种情况下,我试图打开我放置在名为“img”的文件夹中的图像,该文件夹位于我的 java 项目目录中。 Please don't mind the double backslash (\\), I know these only works on Windows, the only thing I wanted to ask if this path relative or absolute.请不要介意双反斜杠 (\\),我知道这些只适用于 Windows,我唯一想问的是这个路径是相对的还是绝对的。

ImageView img = new ImageView(new Image("file:img\\square.png"))

As you can find in the documentation here you can pass to the constructor any URL supported by the URL class, which is the case in your example.正如您在此处的文档中所见,您可以将URL类支持的任何 URL 传递给构造函数,在您的示例中就是这种情况。

If the passed string is not a valid URL, but a path instead, the Image is searched on the classpath in that case.如果传递的字符串不是有效的 URL,而是路径,则在这种情况下在类路径上搜索图像。

In your case, it is relative.在你的情况下,它是相对的。

The file: URL scheme refers to a file on the client machine. file: URL 方案是指客户端计算机上的文件。 There is no hostname in the file: scheme;文件中没有主机名:scheme; you just provide the path of the file.您只需提供文件的路径。 So, the file on your local machine would be file:///~User/2ndFile.html.因此,您本地计算机上的文件将是 file:///~User/2ndFile.html。

Please read this answer for further information.请阅读此答案以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM