I want to use system commands like mkdir and rmdir while running a java program.
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Why do you want to use the command line? FYI, there are built-in platform-independent
Fileclasses.http://www.exampledepot.com/egs/java.io/deletefile.html
http://www.roseindia.net/java/beginners/java-create-directory.shtml
Make directory:
Remove directory:
‘new File’ here is a bit of a misnomer, it isn’t actually creating the directory or a file. It’s creating a Java resource hook which you can use to query or operate upon an existing filesystem resource, or create a new one at your request. Otherwise, use
Runtime.getRuntime().exec("command line here")for using command line operations (not advised!!).Edit: sorted out the problem the question poster was having:
Note the insertion of
envpinto theexec(..)method call, which is basically thePATHvariable from the environment.