阅读 73

fileget软件,可以下载文件和上传文件

package utils; import javax.servlet.servlet output stream; import javax.servlet.http.http servlet request; import javax.servlet.http.http无servlet轮询; import javax.servlet.http.part; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class fileutils (privatestaticstringpath=properties util.read properties (' up _ down _ path ' ) ); publicstaticliststringuploadfile (httpservletrequestrequest ) { ListString list=new ArrayList; try { collectionpartparts=request.get parts (; 部件:部件名称(string filename=p.getsubmittedfilename ); 文件名!=nullfilename.length(0) ) list.add ) filename; p.write(pathfilename; }}catch(exceptione ) { e.printStackTrace ); } return list; } publicstaticvoiddownloadfile (string filename,HttpServletResponse resp ) servletoutputstreamoutputstream=null; try { file file=new file (path filename; resp.set content type (application/octet-stream ); string newname=new string (filename.getbytes (' utf-8 ',' iso-8859-1 ' ); resp.setheader (' content-disposition ',' attachment; filename=' newName; resp.addheader('content-length ',file.length ) )、length ); fileinputstreamfis=new file inputstream (file; byte [] bs=new byte[1024*1024]; int i=-1; 输出流=resp.get输出流(; while((I=fis.read ) ) bs )!=-1 )输出流. write (bs ); outputStream.flush (; }catch(exceptione ) { e.printStackTrace ); } finally { try } if (输出流!=null(outputstream.close ); }catch(ioexceptione ) { e.printStackTrace ); } } }}

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐