Krish Nakum R Krish Nakum R - 1 month ago 8
Java Question

Unable to open file in explorer when there comma in file name

Hi I tried to open a file in explorer for a chat application using java, using the code

Runtime.getRuntime().exec("explorer.exe /select," + recievedFile);


It works fine except when there is
comma(",")
in file name.

I cannot replace
comma(",")
with empty space or some other characters because I have to preserve the file name.

Any other possibilities? Without altering the file name? I must have the file selected and opened in a new explorer window. Thanks.

Answer

You can change your code like this to able to open files with comma in file name:

Runtime.getRuntime().exec("explorer.exe /select,\"" + recievedFile + "\"");