Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing System level commands

 
Naresh Rajan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to make an installable for my application. All i need to do is copy a set of folders into the folder of the users choice. For the front end i am using Swings.

I will be getting the name of the folder (where the appln has to be copied) from the front end. I need to execute a set of commands that will be copying the folders from the CD to the specified location.

This has to be done on both DOS and UNIX.

How do i execute these system level commands from java???
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You execute Windows command prompt or Unix commands by using java.lang.Runtime.exec() - see the API documentation.
 
Eric McIntyre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think at some point you might need to support more than those two platforms, you should copy them yourself using the java.io.File* classes (or java.nio.channels.FileChannel if you want to get fancy). Possibly slower, but insulates you from platform differences.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic