-2

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. 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.

ImageView img = new ImageView(new Image("file:img\\square.png"))
Songg Tùng
  • 139
  • 8

2 Answers2

1

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.

If the passed string is not a valid URL, but a path instead, the Image is searched on the classpath in that case.

Diogo Rocha
  • 9,759
  • 4
  • 48
  • 52
  • Hi, thanks for the answer. Sorry, I'm quite new so from what I understand then since the URL I provided is not a valid URL so the image is searched on the specified path instead, but does the path be classified as relative or absolute? – Songg Tùng Apr 19 '19 at 05:22
-2

In your case, it is relative.

The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html.

Please read this answer for further information.

Nirup Iyer
  • 1,215
  • 2
  • 14
  • 20
  • It is relative to the current working directory, not the user's home directory. The answer you are quoting from is about a URL that already contains `~User`. Your link is to a question, not an answer. – user207421 Apr 19 '19 at 05:22