Date date = new Date(); DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); int sjt = (int) (Math.random()*9000+1000);//随机4位数字 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(); } }
创建一个XML文件
文件名是file+当前日期+思维随机数组合而成;
路径是tomcat的部署路径
时间: 2024-12-25 07:45:15