关闭

java 调用系统命令获MAC、 解压缩 tar包

1103人阅读 评论(0) 收藏 举报

public class procee {

 public static void main(String[] args) {
  try {
   Process process = Runtime.getRuntime().exec("ipconfig /all");
   InputStreamReader ir = new InputStreamReader(process
   .getInputStream());
   LineNumberReader input = new LineNumberReader(ir);
   String line;
   while ((line = input.readLine()) != null)
   if (line.indexOf("Physical Address") > 0) {
   String MACAddr = line.substring(line.indexOf("-") - 2);
   System.out.println("MAC address = [" + MACAddr + "]");
   }
   } catch (java.io.IOException e) {
   System.err.println("IOException " + e.getMessage());
   }
   }  } 

 

 

private boolean upzipTar(String fileName, String targetPath){
  Runtime run = Runtime.getRuntime();
  if(!fileIsExist(fileName)){
   log.debug(fileName+" not found!");
   //文件不存在
   return false;
  }
  String cmd = "tar xZf " + fileName + " -C " + targetPath;
  try {
   
   Process process = run.exec(cmd);
   
   BufferedReader in = new BufferedReader(
     new InputStreamReader(process.getInputStream()));
   if(in.readLine() != null){ //解压缩失败
    log.error("unzip fail "+fileName);
    return false;
   }else{          //解压缩成功
    log.info(" success unzip "+ fileName);
   }
  } catch (IOException e) {
   log.error("IOException occured"+e.getMessage());
  }
  return true;
 }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:18482次
    • 积分:296
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论