国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

利用Java調(diào)用可執(zhí)行命令

2019-11-18 13:50:45
字體:
供稿:網(wǎng)友

  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");  //登錄網(wǎng)站          Process process = Runtime.getRuntime().exec("cmd.exe  /c  start  ping 10.144.98.100");  //調(diào)用Ping命令        }catch (Exception  e)        {            e.printStackTrace();            }                }    }  *///在項目下建立一個名為hello的文件夾    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();     }

 }

在Java程序中獲取當(dāng)前運行程序的路徑



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();取得當(dāng)前路徑





jsp頁面中調(diào)用Ping命令---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"><HTML><head><title>Ping IP測試頁面</title></head>

<body><div align="center">  <h2>Ping IP測試頁面</h2></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";  //待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("</pre>");         is.close();         isr.close();         br.close();     }     catch(IOException  e  )     {         out.println(e);         runtime.exit(1);     }  %> 

</body></HTML>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 昌宁县| 广宗县| 游戏| 卓资县| 新乡市| 定远县| 通州市| 兴仁县| 上虞市| 图木舒克市| 湘阴县| 新营市| 舒兰市| 双城市| 德兴市| 闵行区| 琼中| 合山市| 邵武市| 娱乐| 武川县| 沙河市| 永仁县| 灵璧县| 高州市| 塔城市| 凉城县| 游戏| 鄂尔多斯市| 宝鸡市| 唐山市| 青海省| 满城县| 曲水县| 东至县| 双柏县| 贵阳市| 沧源| 林芝县| 奉节县| 保山市|