getRuntime().exec() problem

In the line below, filename is a String that is the path and filename of an excel file. This works (ie the file is displayed in Excel), except when there is a space in the path. How can this be fixed?

Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", "start", filename });

Open in new window

LVL 1
allelopathAsked:
Who is Participating?
 
Gurvinder Pal SinghConnect With a Mentor Commented:
check this link (scroll down or search for "Path to executable with spaces in them")
http://www.rgagnon.com/javadetails/java-0014.html
0
 
ValeriCommented:
Try this:
Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", "start", "\"" + filename + "\"" });
0
 
allelopathAuthor Commented:
From the link, this works:
String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};

That DummyTItle is necessary, doesn't work without it. What does it do?
0
 
ValeriConnect With a Mentor Commented:
This Dummy title is needed only for windows. If start command sees a string it takes it as a title of the command window. That's way the dummy title is needed, otherwise the real filename is considered as a title of the command window.
0
All Courses

From novice to tech pro — start learning today.