1

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.

Krish Nakum R
  • 505
  • 1
  • 8
  • 19
  • Possible duplicate of http://stackoverflow.com/questions/161859/using-quotes-within-getruntime-exec – KC Wong Oct 27 '16 at 06:40
  • Does surrounding the name with double quotes work? And do you really have a file that is called `comma(",")`? Can you add the **real** filename? –  Oct 27 '16 at 06:43
  • See also [When Runtime.exec() won't](http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html) for many good tips on creating and handling a process correctly. Then ignore it refers to `exec` and use a `ProcessBuilder` to create the process. Also break a `String arg` into `String[] args` to account for things like paths containing space characters (or comma characters). – Andrew Thompson Oct 27 '16 at 09:13

1 Answers1

1

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

Runtime.getRuntime().exec("explorer.exe /select,\"" + recievedFile + "\"");
Daniyar
  • 815
  • 1
  • 9
  • 22