java啟動dos命令收集信息筆記一
創(chuàng)新互聯(lián)是專業(yè)的運城網(wǎng)站建設(shè)公司,運城接單;提供網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行運城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.Test;
public class Person {
@Test //使用testng作為入口
public void doscmd() throws InterruptedException
{
System.out.println(System.getProperty("os name")); //判斷當(dāng)前系統(tǒng)
Person p = new Person();
List<String> dL = p.excmd("adb devices"); //調(diào)用函數(shù)執(zhí)行adb devices命令
System.out.println(dL.size());
for (String s:dL) { //通過增強for循環(huán)輸出內(nèi)容。 s--定義變量,dl--為adb devices內(nèi)容
System.out.println(s); //輸出顯示
}
}
public List<String> excmd(String cmdString) throws InterruptedException {
List<String> dosCMd = new ArrayList<String>(); //定義一個List集合
Process process = null; //定一個Process ID號
try {
process = Runtime.getRuntime().exec(cmdString); //通過內(nèi)置函數(shù)啟動exec命令
InputStream in = process.getInputStream(); //通過輸出流輸出
BufferedReader inR = new java.io.BufferedReader(new InputStreamReader(in));
String line = null;
while((line = inR.readLine()) != null) //通過while遍歷命令行信息
{
dosCMd.add(line);
}
System.out.println("成功取出");
} catch (IOException e) {
System.out.println("數(shù)據(jù)不能獲取");
e.printStackTrace();
}
process.waitFor();
process.destroy();
return dosCMd;
}
網(wǎng)頁題目:java啟動dos命令收集筆記一
轉(zhuǎn)載注明:http://chinadenli.net/article28/jggpcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、Google、定制開發(fā)、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計公司、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)