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

本文介绍了一个简单的Java程序,用于监测特定文件的下载进度,并在指定文件下载完成后自动执行计算机关机操作。程序通过检查文件名变化来判断下载状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前天下载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);

}

}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值