这是上传文件代码的相关java代码,我需要为文件名添加时间戳,然后将其上传到特定目录
public class Upload extends httpServlet { private static final long serialVersionUID = 1L; public voID init() throws servletexception { System.out.println(this.getClass().getname()); } protected voID doPost(httpServletRequest request,httpServletResponse response) throws servletexception,IOException { //boolean MultipartRequest; //String PrintWriter; response.setContentType("text/HTML"); PrintWriter out = response.getWriter(); MultipartRequest multipartRequest = new MultipartRequest(request,"/home/hadoop/Desktop"); out.println("succcesfully uploaded"); } public voID destroy() { System.out.println(this.getClass().getname()); } }
最佳答案默认情况下,MultipartRequest包含文件重命名策略.To avoID collisions and have fine control over file placement,there’s a constructor varIEty that takes a pluggable fileRenamePolicy implementation. A parti@R_502_6603@r policy can choose to rename or change the location of the file before it’s written.
MultipartRequest(javax.servlet.http.httpServletRequest request,java.lang.String saveDirectory,int maxpostsize,fileRenamePolicy policy)
注意:由于声誉低,我无法添加评论,不得不作为答案贡献.不要低估这一点,而是纠正或评论. 总结
以上是内存溢出为你收集整理的java – 如何在上载文件时为文件名添加时间戳全部内容,希望文章能够帮你解决java – 如何在上载文件时为文件名添加时间戳所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)