81,090
社区成员
发帖
与我相关
我的任务
分享
//本地程序集版本号与数据库保存的版本号不一致时将提示用户系统升级
if (bi.CurrentSysVersion.ToString() != bi.SysVersion.ToString().Trim())
{
if (MessageBox.Show("发现新版本,需要更新吗?", "System Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
if (System.IO.File.Exists(@"D:\DownLoad"))
{
System.IO.File.Delete(@"D:\DownLoad");
}
System.IO.Directory.CreateDirectory(@"D:\DownLoad");
System.Net.WebClient wc = new System.Net.WebClient();
//以下三句是将目标网站的安装包下载到本地,并且运行
wc.DownloadFile("http://172.19.84.6:9475/File/试作订单导出系统/setup.exe", @"D:\DownLoad\setup.exe");
wc.DownloadFile("http://172.19.84.6:9475/File/试作订单导出系统/OrderConvertSetup.msi", @"D:\DownLoad\OrderConvertSetup.msi");
if (bi.getOS_Type() != "ja-JP" && bi.getOS_Type() != "ja")
{
System.Diagnostics.Process.Start(@"D:\DownLoad\setup.exe"); //中文版操作系统直接运行exe文件
}
else
{
System.Diagnostics.Process.Start(@"D:\DownLoad\PWCS_Setup.msi"); //日文版操作系统无法直接运行exe文件,需要运行msi文件
}
bi.KillTheProcess(); //终止当前程序的进程
}
}
URL url = new URL(strurl);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
int size = conn.getContentLength();
double oldCompleted = 0;
double completed = 0;
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(new FileOutputStream(
downloadFile));
boolean downLoading = true;
byte[] buffer = new byte[BUFFER_SIZE];
int downloaded = 0;
int read;
while ((downLoading) && (!mAborted)) {
if ((size - downloaded < BUFFER_SIZE)
&& (size - downloaded > 0)) {
buffer = new byte[size - downloaded];
}
read = bis.read(buffer);
if (read > 0) {
bos.write(buffer, 0, read);
downloaded += read;
} else {
downLoading = false;
}
// Notify each 5% or more.
if (oldCompleted + 5 < completed) {
mParent.onProgress((int) completed);
oldCompleted = completed;
}
}
} catch (MalformedURLException mue) {
mParent.setErrorMessage(mue.getMessage());
}
是这样下载的,strurl就是我上面举例的地址[/quote]
LZ按照上面说的那样,要分析你现在请求的URL,并使用浏览器看看httpheadr里面的内容
URL url = new URL(strurl);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
int size = conn.getContentLength();
double oldCompleted = 0;
double completed = 0;
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(new FileOutputStream(
downloadFile));
boolean downLoading = true;
byte[] buffer = new byte[BUFFER_SIZE];
int downloaded = 0;
int read;
while ((downLoading) && (!mAborted)) {
if ((size - downloaded < BUFFER_SIZE)
&& (size - downloaded > 0)) {
buffer = new byte[size - downloaded];
}
read = bis.read(buffer);
if (read > 0) {
bos.write(buffer, 0, read);
downloaded += read;
} else {
downLoading = false;
}
// Notify each 5% or more.
if (oldCompleted + 5 < completed) {
mParent.onProgress((int) completed);
oldCompleted = completed;
}
}
} catch (MalformedURLException mue) {
mParent.setErrorMessage(mue.getMessage());
}
是这样下载的,strurl就是我上面举例的地址