当前位置:   article > 正文

java exec执行tar_java 调用系统命令获MAC、 解压缩 tar包

java调用process打包tar

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; }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/1000062
推荐阅读
相关标签
  

闽ICP备14008679号