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

java程序调用wget.exe下载文件

2017-01-10 11:00 405 查看
wget命令

e:\wget  -r -c  --limit-rate=1M -t 10  -T 60  -o d:\wgetlog\result.txt -O E:\projectTest/rhq-agent-update.log http://xxxx:8280/../opt/app/install/rhq-agent-update.log[/code] 
程序关键代码

String cmd = wgetPath+"\\wget  -r -c  --limit-rate=1M -t 10  -T "+timeoutms+"  -o " + logPath + " -O " + filePath + " " + url;
Process download=Runtime.getRuntime().exec(cmd);
download.waitFor();
new Thread () {
public void run() {
logger.info("start resultFile monitor!");
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e)  {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader reader = null;;
try {
reader = new BufferedReader(new FileReader(logFile));
while(true) {
String line = reader.readLine();
if (line != null) {
logger.debug(line);
} else {
break;
}
}
break;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
validateFile();
}

public void validateFile() {
File download = new File(filePath);
try {
if(download.length() > 0) {
DownloadXMLConfig.setFileStatus(verNum,fileName, "download");
}else{
DownloadXMLConfig.setFileStatus(verNum,fileName, "fail");
if (download.exists()) {
download.delete();
}
}
} catch (Exception e) {
// TODO: handle exception
logger.error("DownloadXMLConfig setFileStatus exception : "+e);
}
}
}.start();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: