您的位置:首页 > 编程语言 > Java开发

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

2007-09-21 17:35 260 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: