Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
First of all, there is no need whatsoever to create Stringst like that. You can simply use pa.
Second, you cannot execute any file, only executables and batch files. Anything else needs another application to run it.
Fortunately, you don't have to do any more hard work, using java.awt.Desktop that was introduced in Java 6. That same code snippet using the new class:
That will open the file with its default application. Yes, it's that simple these days.
OK, and now the more complex version that does some actual checking:
This uses the "magic" rundll32 url.dll,FileProtocolHandler command to use to execute the file with its default application. Of course this is only available on Windows.
Also, whenever you use Runtime.exec or ProcessBuilder, make sure to have read and understood When Runtime.exec() won't. It's an old article, but still very accurate. The only difference is that when you use ProcessBuilder with a redirected error stream, you don't need to read anything from p.getErrorStream().
Also, be aware of Concurrency in Swing. If you're not careful you may end up blocking the Event Dispatcher Thread, effectively making your entire user interface not respond to anything, including repaint requests from the operating system.
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth