Using Java calls the executive command instance

xiaoxiao2021-03-06  70

Package test;

/ ** * Add one. * Add class description her. * * @Author lxx * @version 1.0, 2004-11-16 * / public class testcmd {public testcmd () {} / * public void main String args []) {Try {process = runtime.getRuntime (). EXEC ("cmd.exe / c start http://www.9cbs.net"); // Login Website Process Process = runtime.Getruntime () .exec ("cmd.exe / c start ping 10.144.98.100"); // calls ping command} catch (Exception E) {E.PrintStackTrace ();}}} * /// Under the project, a named Hello is established. Folder 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.seParetor foldername; java.io.file f = new java.io.file (TEMP); f .mkdirs ();

}

Get the path to 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 in the JSP page --- pingip.jsp <% @ page language = "java" contenttype = "text / html; charset = GB2312" Import = "java.io. *"%> "HEAD ">PING IP Test Page

ping ip test page

<% 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"; / / Try to be ping Try {process = runtime.exec ("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 (" "); is.close (); Isr.close (); br.close ();} catch (ioexception e) {OUT.Println (E); runtime.exit (1);}%>

转载请注明原文地址:https://www.9cbs.com/read-89053.html

New Post(0)