zoukankan
html css js c++ java
使用WebClient进行上传文件 [ZT]
private
bool
UploadFile(
string
source,
string
targetUrl,NetworkCredential networkCredential)
{
FileStream streamSource;
Stream streamTarget;
WebClient client
=
new
WebClient();
client.Credentials
=
networkCredential;
try
{
streamSource
=
File.OpenRead(source);
}
catch
(Exception err)
{
return
false
;
}
try
{
Uri url
=
new
Uri(targetUrl);
streamTarget
=
client.OpenWrite(url,
"
PUT
"
);
}
catch
(Exception err)
{
return
false
;
}
try
{
long
num
=
0
;
int
count
=
0
;
byte
[] buffer
=
new
byte
[
512
];
while
(num
<
streamSource.Length)
{
count
=
streamSource.Read(buffer,
0
,
512
);
streamTarget.Write(buffer,
0
, count);
num
+=
count;
}
streamTarget.Close();
streamSource.Close();
return
true
;
}
catch
(Exception err)
{
return
false
;
}
}
查看全文
相关阅读:
spring cloud网关gateway
maven将依赖第三方包打包(package)到jar中
spring boot创建多模块聚合工程
spring cloud服务间调用feign
取模和取余的区别
实现多线程编程的三种方式
打开eclipse编译后的.class文件
对中断interrupt的理解
对final和static的理解
对synchronized的一点理解
原文地址:https://www.cnblogs.com/RobotTech/p/928856.html
最新文章
php大流量高并发解决方案
PHPer是草根吗
最近知识点
PHP常用算法和数据结构示例
php实现链表的基本操作
MySQL DATE_FORMAT() 函数
MySQL字符串函数:字符串截取
nginx timeout 配置 全局timeout 局部timeout web timeout
Nginx proxy buffer相关的设置和解释
Spring中使用JMS
热门文章
xargs命令
Nginx 基于客户端 IP 来开启/关闭认证
Git远程操作详解
基于 Annotation 的 Spring AOP 权限验证方法的实现
Javad的Validator框架概述
curl发json
redis集群安装多端口多实例部署
spring boot配置项profiles active
spring boot集成mybatis
Invalid bound statement (not found)--spring boot集成mybatis
Copyright © 2011-2022 走看看