java中怎么把文件上传到服务器的指定路径

java中怎么把文件上传到服务器的指定路径,第1张

string
realpath
=
servletactioncontextgetservletcontext()getrealpath("/upload")
;//获取服务器路径
string[]
targetfilename
=
uploadfilename;
for
(int
i
=
0;
i
<
uploadlength;
i++)
{
file
target
=
new
file(realpath,
targetfilename[i]);
fileutilscopyfile(upload[i],
target);
//这是一个文件复制类copyfile()里面就是io *** 作,如果你不用这个类也可以自己写一个io复制文件的类
}
其中private
file[]
upload;//
实际上传文件
private
string[]
uploadcontenttype;
//
文件的内容类型
private
string[]
uploadfilename;
//
上传文件名
这三个参数必须这样命名,因为文件上传控件默认是封装了这3个参数的,且在action里面他们应有get,set方法


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13054673.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-30
下一篇 2023-05-30

发表评论

登录后才能评论

评论列表(0条)

保存