Reputation: 15
How to make a JFileChooser return the file path in the format, that Java could open the file?
.getPath() returns the path with \ (on Windows), but I want it to return the path with / Is this possible?
Greeting Ra1ningSn0w
Upvotes: 0
Views: 390
Reputation: 81
The method getSelectedFile()
of JFileChooser
will return a File
object that is enough to open a file. If you don't want this file to open, but only to return its path, you can call File
's method getAbsolutePath()
. It will return a file path in form dependent on operating system.
To get the path use (fc
is JFileChooser
object):
String path = fc.getSelectedFile().getAbsolutePath().replace('\\', '/');
Upvotes: 1