会员
周边
新闻
博问
闪存
赞助商
YouClaw
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
冷风.NET
---默默無聞
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
斷點傳輸
Posted on
2004-11-25 09:04
冷风.net
阅读(
570
) 评论(
1
)
收藏
举报
string
strFileName
=
"
d:\\aa.rar
"
;
string
strUrl
=
"
http://192.168.1.9/Artmall/HML.rar
"
;
public
Class1()
{
}
public
void
upFile()
{
//
打開上次下載文件或新建文件
long
iStartPos
=
0
;
System.IO.FileStream fs;
if
(System.IO.File.Exists(strFileName))
{
fs
=
System.IO.File.OpenWrite(strFileName);
iStartPos
=
fs.Length;
fs.Seek(iStartPos,System.IO.SeekOrigin.Current);
//
移動文件流中的當前指針
}
else
{
fs
=
new
System.IO.FileStream(strFileName,System.IO.FileMode.Create);
iStartPos
=
0
;
}
//
打開網絡連接
try
{
System.Net.HttpWebRequest request
=
(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(strUrl);
if
(iStartPos
>
0
)
request.AddRange((
int
)iStartPos);
//
設置Range的值,Range表示從何處開始下載
//
向服務器請求、獲得服務器回應數據流
System.IO.Stream ns
=
request.GetResponse().GetResponseStream();
byte
[] nbytes
=
new
byte
[
512
];
int
nReadSize
=
0
;
nReadSize
=
ns.Read(nbytes,
0
,
512
);
while
(nReadSize
>
0
)
{
fs.Write(nbytes,
0
,nReadSize);
nReadSize
=
ns.Read(nbytes,
0
,
512
);
}
fs.Close();
ns.Close();
}
catch
(System.Exception exc)
{
fs.Close();
throw
new
Exception(
"
It's Error for Down Files--->
"
+
exc.ToString());
}
}
刷新页面
返回顶部
博客园
© 2004-2026
浙公网安备 33010602011771号
浙ICP备2021040463号-3