JAVA to create a simple file

Source: Internet
Author: User
                 date date  = new date ();D Ateformat formatter = new simpledateformat ("YyyyMMddHHmmss") ;int sjt =  (int)   (math.random () *9000+1000);//random 4-digit string newxmlname =  " File "+formatter.format (date) +sjt+". xml "; String path = servletactioncontext.getservletcontext (). Getrealpath ("/"); string xmlpath = path+ "/xmlfile/"; File xmlfile = new file (Xmlpath+newxmlname); if (!xmlfile.exists ()) {try { Xmlfile.createnewfile ();}  catch  (IOEXCEPTION E1)  {e1.printstacktrace ();}} 

Create an XML file

The


File name is a combination of file+ current date + thought random number;


Path is a deployment path for Tomcat

This article is from the "Oriental Pavilion" blog, please be sure to keep this source http:/ lailai.blog.51cto.com/3362373/1588797

JAVA to create a simple file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.