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 = runtime.getruntime(cmd.exe C ("cmd.exe/C start http://www.csdn.net"); // log on to the website
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 ();
}
}
Obtain the path of the current 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 --- 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 </H2>
</Div>
<%
Runtime runtime = runtime. getruntime ();
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>