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 ); } } }}