Scitech
Scitech

Reputation: 535

Read forward slash from JFileChooser file-name dialog

I need to read a file name from JFileChooser file-name input dialog which consist of forward slash '/'. But it's taking as a backslash '\' Path Separator in windows environment.

Upvotes: 1

Views: 245

Answers (1)

akhil_mittal
akhil_mittal

Reputation: 24157

Actually JFileChooser will return the path suitable for the machine it is running on. In case of windows it is backward slash and for Mac it is forward slash. The JFileChooser returns a File object and by calling getCanonicalPath you get the path which has a different format depending on the OS.

SO IMO there seems to be no clean way at least. One possibility is to read the file name and then replace backward slash with forward slash. But I doubt it will work for you.

Upvotes: 1

Related Questions