Package test;
/**
* Add one sentence class summary here.
* Add class description here.
*
* @ Author lxx
* @ Version 1.0
*/
Public class TestCmd {
Public TestCmd (){}
/* Public void main (String args []) {
Try {
Process process = runtime.getruntime(cmd.exe c ("cmd.exe/c start http://www.csdn.net"); // log on to the website
Process process = runtime.getruntime(cmd.exe c ("cmd.exe/c start ping 10.144.98.100"); // call the 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 ");
}
Private Static void createfolder (string Foldername ){
String temp = system. getproperty ("user. dir") + Java. Io. file. Separator + Foldername;
Java. Io. File F = new java. Io. File (temp );
F. mkdirs ();
}
}
InJavaObtain the path of the current running program in the 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 --- PingIP. Jsp on the jsp page
<% @ 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">
<Html>
<Head>
<Title> Ping IP test page </title>
</Head>
<Body>
<Div align = "center">
<H2> Ping IP test page </Div>
<%
Runtime runtime = Runtime. getRuntime ();
Process process = null;
String line = null;
InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
String ip = "www.sina.com.cn"; // address to be pinged
Try
{
Process worker runtime.exe c ("ping" + ip );
Is = process. getInputStream ();
Isr = new InputStreamReader (is );
Br = new BufferedReader (isr );
Out. println ("<pre> ");
While (line = br. readLine ())! = Null)
{
Out. println (line );
Out. flush ();
}
Out. println ("</pre> ");
Is. close ();
Isr. close ();
Br. close ();
}
Catch (IOException e)
{
Out. println (e );
Runtime. exit (1 );
}
%>
</Body>
</Html>