`
geeksun
  • 浏览: 950952 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

FlashGet下载完自动关机的小程序

阅读更多

前天下载ubutn的10.04版本ubuntu-10.04.1-desktop-i386.iso,因为公司设置了网速限制,使用快车FlashGet下载每秒只60K左右,到天黑走时还有80多M没下完,就写了一个下载任务完成后自动关机的小程序,原理是定时判断下载文件所存放的文件夹下有没有该文件的名字,因为在下载未完成时,文件夹里下载的文件的名字是ubuntu-10.04.1-desktop-i386.iso.jc和ubuntu-10.04.1-desktop-i386.iso.jccfg3,下载完成后,文件的名字就成了本来的名称——ubuntu-10.04.1-desktop-i386.iso。

程序如下:


import java.io.File;

import java.io.IOException;


public class TimeShutdown {

public static void shutDownComputer(int times) {

Runtime run = Runtime.getRuntime();

try {

run.exec("shutdown -s -t" + " " + times);

} catch (IOException e) {

e.printStackTrace();

}

}

static void checkProgress(){

File f = new File("D:\\Downloads");

File[] tt = f.listFiles();

System.out.println("Now Time:"+System.currentTimeMillis());

for(int i=0;i<tt.length;i++){

if(tt[i].isDirectory()){

;

}

else{

System.out.print("File:");

String fn = tt[i].getName();

System.out.println(fn);

if(fn.equals("ubuntu-10.04.1-desktop-i386.iso")){

System.out.println("ubuntu-10.04.1-desktop-i386.iso Download Complete!");

shutDownComputer(10);

}

}

}

}


/**

* @param args

* @throws InterruptedException 

*/

public static void main(String[] args) throws InterruptedException {

while(true){

checkProgress();

Thread.sleep(300000);

}

}

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics