多谢!代码如下:
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add ("user-agent", "WinampMPEG/2.7");
client.DownloadFile("http://localhost/m3uplay/tomp3.asp?SongID=148040","d:\\c.mp3");
这样得到的结果是一个5.01Mb的文件。
如果这样:
System.IO.Stream str = client.OpenRead("http://localhost/m3uplay/tomp3.asp?SongID=148040");
System.IO.FileStream fs = new FileStream("d:\\this.mp3",System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.Read);
byte[] buffer = new byte[1024];
int count;
int ps=0;
for(;;)
{
count=str.Read(buffer,0,1024);
ps+=count;
fs.Write(buffer,0,1024);
down=((float)ps)/(2048*1024);
fs.Flush();
if(count==0)break;
}
fs.Close();
str.Close();
这样得到的就是一个6M的文件,而且mp3播放起来很刺耳。
这是怎么回事?我要怎样能得到正确的结果呢?
btw:我最近总是觉得我在网络方面基础很差,可否推荐一些书来读?
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add ("user-agent", "WinampMPEG/2.7");
client.DownloadFile("http://localhost/m3uplay/tomp3.asp?SongID=148040","d:\\c.mp3");
这样得到的结果是一个5.01Mb的文件。
如果这样:
System.IO.Stream str = client.OpenRead("http://localhost/m3uplay/tomp3.asp?SongID=148040");
System.IO.FileStream fs = new FileStream("d:\\this.mp3",System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.Read);
byte[] buffer = new byte[1024];
int count;
int ps=0;
for(;;)
{
count=str.Read(buffer,0,1024);
ps+=count;
fs.Write(buffer,0,1024);
down=((float)ps)/(2048*1024);
fs.Flush();
if(count==0)break;
}
fs.Close();
str.Close();
这样得到的就是一个6M的文件,而且mp3播放起来很刺耳。
这是怎么回事?我要怎样能得到正确的结果呢?
btw:我最近总是觉得我在网络方面基础很差,可否推荐一些书来读?
解决方案 »
- EntityFramework问题,
- 如何在非窗体的类库中用多线程时避免线程冲突?
- pop3 新邮件数目如何取?求个办法
- 窗体文件*.Desinger.cs内容丢失
- 请问做项目时用 相对路径好 还是 绝对路径好?
- 请问 easyMail 导致发送失败的原因有哪些呀
- [请问] 什么方法可以在服务器端(cs)文件里面+一些代码或则是一些方法呢? (开发服务器控件)
- 散分了,高手请进---.net不能够bug
- asp+和c#什么关系?
- C#读取数据库数据出现问题,无法读取到第一行与第一列
- 关于两个datagrid的问题,大家来看看,新手问题!!
- java技术高手联盟(12309569)和c#联谊会(11019078)挺不错的
fs.Write(buffer,0,count);这样才对。
那这个帖子怎么办?分就分给荐书者了呀
C# Network Programming by Richard Blum