• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaFX: How to access pictures outside the directory of the program

 
Nicholas d'Hondt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would I set the filepath as if the program was in Documents and the image was in Program files (x86)?


Should I just make a copy of those pictures in the program's directory?
 
Campbell Ritchie
Sheriff
Posts: 51368
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth would you put an image in the Program Files directory? Of course you should put the images in the same directory as the JavaFX code. Just be careful; it is quite easy to get confused about the exact path, as in this recent thread.

I think this discussion would fit better in the FX forum, so I shall move it.
 
Nicholas d'Hondt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look, does it matter? Program Files (x86) was just an example of a file that has a completely different directory.

Say I wanted the Chrome logo, but didn't want to copy/paste it in the same directory for whatever reason. This is it's directory: C:\Program Files (x86)\Google\Chrome\Application\45.0.3955.134\VisualElements\logo.png

I know I would have to add a '\' for every '\' already in there, but is there anything else I would have to do to make the program find the right place? Because I did that and it doesn't work.
 
Paul Clapham
Sheriff
Posts: 21565
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd just provide the full path to the image file... but it looks like you knew that already. It looks like you didn't know about the use of \ as an escape character in string literals, though. (I'm just guessing, though, you didn't provide many details, but that's where you post is pointing me.)

I'd suggest using slashes to separate directories in file paths, even Windows file paths. Java supports that perfectly well and you don't need to mess about escaping backslashes. Like "C:/Program Files (x86)/Google/Chrome/..." for example.

(Unless you're trying to use a file path where a URL is required, but that's an even wilder guess.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic