Ra1ningSn0w
Ra1ningSn0w

Reputation: 15

Path from JFileChooser in Java Format

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

Answers (1)

Kordyjan
Kordyjan

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

Related Questions