private void picturedownload()
{
try
{
WebRequest request = WebRequest.Create(URI); //创建了request对象,向服务器发送请求
HttpWebResponse response = (HttpWebResponse)request.GetResponse();//将得到的响应传给响应对象response
Stream st = response.GetResponseStream();
int buffersize = 10000;
byte[] bt = new byte[buffersize]; //创建文件缓冲
FileStream write = new FileStream(filename, FileMode.OpenOrCreate);
int intbuffer = st.Read(bt, 0, buffersize);
while (intbuffer > 0)
{
write.Write(bt, 0, intbuffer);
intbuffer = st.Read(bt, 0, buffersize);
}
st.Close();
write.Close();
response.Close();
directory();
bt=null;
}
catch (Exception ex )
{
MessageBox.Show("没有下载成功!"+ex.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog folder;
folder = new FolderBrowserDialog();//创建保存对象
folder.ShowDialog();
folderselect = folder.SelectedPath;
textBox5.Text = folderselect;
}
private void directory()
{
folder1 = "L" + textBox2.Text;
folder1X = R.ToString("x8");//将字符串转换为8位16进制
folderpath1 = folderselect + @"\" + folder1; //创建一级目录
Directory.CreateDirectory(folderpath1);
folderpath2 = folderpath1 + @"\" + "R"+folder1X;
Directory.CreateDirectory(folderpath2);//创建二级目录
folder2X =C.ToString("x8");//将字符串转换为8位16进制
filename = folderpath2 + @"\" +"C"+folder2X+ ".jpg";
}
问: FileStream write = new FileStream(filename, FileMode.OpenOrCreate);这句话会对文件夹有影响吗?
因为我是循环下载多张,都在同一文件夹下创建文件,这句话对文件下载有问题吗?怎么解决呢???
6 个解决方案
#1
#2
提示你路径为空,看看是不是没赋值
#3
FileStream write = new FileStream(filename, FileMode.OpenOrCreate);
这里的filename要先判断路径是不是存在。
这里的filename要先判断路径是不是存在。
#4
我已解决,仍旧感谢!!!
#5
谢,已解决!!!
#6
平安夜了,没苹果送10分
#1
#2
提示你路径为空,看看是不是没赋值
#3
FileStream write = new FileStream(filename, FileMode.OpenOrCreate);
这里的filename要先判断路径是不是存在。
这里的filename要先判断路径是不是存在。
#4
我已解决,仍旧感谢!!!
#5
谢,已解决!!!
#6
平安夜了,没苹果送10分