Using Java to invoke an executable command instance
Source: Internet
Author: User
Execute Package test;
/**
* ADD one sentence class summary here.
* Add class description here.
*
* @author LXX
* @version 1.0, 2004-11-16
*/
public class testCMD {
Public testCMD () {}
/* public void Main (String args[]) {
try {
Process process = Runtime.getruntime (). EXEC ("cmd.exe/c start Http://www.csdn.net"); Login site
Process process = Runtime.getruntime (). EXEC ("cmd.exe/c start ping 10.144.98.100"); Invoke ping command
}catch (Exception e)
{
E.printstacktrace ();
}
}
} */
Create a folder named Hello under the project
public static void Main (string[] args) {
System.out.println (System.getproperty ("User.dir"));
CreateFolder ("Hello");
}
To get the path of the currently running program in the Java program
Import java.io.*;
public class Test {
public static void Main (string[] args) {
File directory = new file (".");
try {
File NewPath = new file (Directory.getcanonicalpath () + "NewFolder");
Newpath.mkdir ();
}catch (Exception exp)
{
Exp.printstacktrace ();
}
}
}
File directory = new file (".");
Directory.getcanonicalpath (); Get the current path
Call the ping command in the JSP page---pingip.jsp
<%@ page language= "java" contenttype= "text/html; charset=gb2312 "import=" java.io.* "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service