简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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