Is it possible to let user enters a path with quotes in JFileChooser and get this path without quotes?
For example the user puts: "c:\path\to\File" in the File name text field. but when I got the selected file I got the current directory + "c:\path\to\File". Is their a way to solve this problem?
Thanks,
You could do something like so:
prints:
This will remove the quotes (
") which are exactly at the beginning and end of the string. The?in the regular expression denotes that the quotes might not be there, so for instance, the following should all yield the same result:However, to my knowledge, the
"character does not make part of a valid file path, so you might get around just by doing:str.replaceAll("\"","");.EDIT: Seeing your comment and question edit, I made this short piece of code which seems to do what you are after. That said, I will not be removing my previous answer just in case someone else might find it useful.
This seems to do what you are after, I have pasted the following in the File text box:
"C:\foo\bar.txt"and the code printedC:\foo\bar.txt, excluding the initial segment.