Java Build file
1. Description
takes a file path as a parameter, infers whether the file exists, and creates the file if it does not exist. and output file path
2. Implement source code
/** * @Title: Buildfile.java * @Package: Com.you.freemarker.model * @Description: Generate file * @author: Youhaidong (Zhanghaidong) * @date : 2014-6-30 PM 10:28:42 * @version V1.0 */package com.you.freemarker.model;import java.io.file;/** * Class Function Description * Class Change date * Change said Ming * <p>Title:BuildFile.java</p> * <p>description: Zhanghaidong personal Development </p> * <p>copyright:copyright ( c) 2013</p> * @author: Zhanghaidong * @date: 2014-6-30 pm 10:28:42 * @version V1.0 */public class BuildFile {/** * infer if the file exists. Create file if not present * @Title: BuildFile * @Description: * @param: @param path * @param: @return * @return: String * @throws */Public static string BuildFile (string path) {//Gets the file path as well as the file name, FileName: ' New file ' (path); If the file does not exist if (!file.exists ()) {try {//Create file File.createnewfile ();} catch (Exception e) {e.printstacktrace ()}} return path; }/** * @Title: Main * @Description: * @param: @param args * @return: void * @throws */public static void Main (string[] args) {//file path created by string path = "d:\\myeclipse\\workspace\\file.ftL ";//Call file generation method String FilePath = buildfile (path); Print the path to the generated file System.out.println ("Generated file path:" +filepath);}}
3. Achieve Results
(1) Console print results
Generated file path: D:\MYECLIPSE\WORKSPACE\FILE.FTL
(2) Generated files
Java Build file