java ftp获取文件夹大小,java 用FTPClient 下载文件时不显示总大小?解决方案
java 用FTPClient 下載文件時(shí)不顯示總大小?
FTPClient?ftp?=?new?FTPClient();
ftp.setControlEncoding("utf-8");
OutputStream?outputStream?=?null;
try?{
int?reply;
//?連接FTP服務(wù)器
//?如果采用默認(rèn)端口,可以使用ftp.connect(url)的方式直接連接FTP服務(wù)器
ftp.connect("192.168.1.111");
//?登錄ftp
ftp.login("zhanghao",?"mima");
reply?=?ftp.getReplyCode();
if?(!FTPReply.isPositiveCompletion(reply))?{
ftp.disconnect();
}
response.setHeader("Content-Disposition","attachment;?filename=\""+new?String(filename.getBytes("gbk"),"iso8859-1")+"\"");
//?將文件保存到輸出流outputStream中
InputStream?in?=?ftp.retrieveFileStream(ftppath);
FTPListParseEngine?engine?=?ftp.initiateListParsing(ftppath);
outputStream?=?response.getOutputStream();
int?len?=?0;
long?size?=?0;
byte[]?bt?=?new?byte[1024];
while?((len?=?in.read(bt))?>?0)?{
outputStream.write(bt,?0,?len);
size?=?size?+?len;
}
outputStream.flush();
outputStream.close();
ftp.logout();
response.setStatus(HttpServletResponse.SC_OK?);
response.flushBuffer();
}?catch?(IOException?e)?{
}?finally?{
if?(ftp.isConnected())?{
總結(jié)
以上是生活随笔為你收集整理的java ftp获取文件夹大小,java 用FTPClient 下载文件时不显示总大小?解决方案的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2019最火的50首歌
- 下一篇: php中数组生成下拉选项,php利用数组