Can we call 开发者_运维知识库a Windows cmd command in Java? For example, calling the "unzip" command of Windows in a Java program. Would that be difficult?
Yes, that's possible. The most basic API which Java SE provides for this is the Runtime#exec()
. It has some known traps though, this article is an excellent read: When Runtime.exec() won't.
Note that Java SE provides the java.util.zip
package as well for zipping/unzipping files programmatically. See also this article for a guide.
yes you can do it,USE
**Runtime.getRuntime().exec("your command");**
I would suggest using the newer class ProcessBuilder: http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html
It holds your hand a little bit more and it allows you to merge the error and stdout streams so that you don't have to have two streamgobbler threads running.
精彩评论