zoukankan      html  css  js  c++  java
  • Java生成文件

    Java生成文件


    1、说明

          以文件路径作为參数,推断该文件是否存在,若不存在就创建文件。并输出文件路径


    2、实现源代码

    /**
     * @Title:BuildFile.java
     * @Package:com.you.freemarker.model
     * @Description:生成文件
     * @author:Youhaidong(游海东)
     * @date:2014-6-30 下午10:28:42
     * @version V1.0
     */
    package com.you.freemarker.model;
    
    import java.io.File;
    
    /**
     * 类功能说明
     * 类改动者 改动日期
     * 改动说明
     * <p>Title:BuildFile.java</p>
     * <p>Description:游海东个人开发</p>
     * <p>Copyright:Copyright(c)2013</p>
     * @author:游海东
     * @date:2014-6-30 下午10:28:42
     * @version V1.0
     */
    public class BuildFile 
    {
    	/**
    	 * 推断文件是否存在。若不存在就创建文件
    	 * @Title:buildFile
    	 * @Description:
    	 * @param:@param path
    	 * @param:@return
    	 * @return:String
    	 * @throws
    	 */
        public static String buildFile(String path)
        {
        	//获取文件路径以及文件名称
        	File file = new File(path);
        	//若文件不存在
        	if (!file.exists()) 
        	{
    			try 
    			{
    				//创建文件
    				file.createNewFile();
    			} 
    			catch (Exception e) 
    			{
    				e.printStackTrace();
    			}
    		}
    		return path;
        }
    	/**
    	 * @Title:main
    	 * @Description:
    	 * @param:@param args
    	 * @return: void
    	 * @throws
    	 */
    	public static void main(String[] args) 
    	{
    		//创建的文件路径
    		String path = "D:\MyEclipse\workspace\file.ftl";
    		//调用文件生成方法
            String filePath = buildFile(path);
            //打印生成文件的路径
            System.out.println("生成的文件路径:"+filePath);
    	}
    
    }
    

    3、实现结果

    (1)控制台打印结果

    生成的文件路径:D:MyEclipseworkspacefile.ftl


    (2)生成的文件


  • 相关阅读:
    Goal driven performance optimization
    Using SHOW PROCESSLIST and mysqladmin debug Output in Conjunction with SHOW INNODB STATUS
    Concurrent inserts on MyISAM and the binary log
    A better SHOW TABLE STATUS
    show table status
    A Flock Of Tasty Sources On How To Start Learning High Scalability
    PostgreSQL Hardware Performance Tuning
    Choosing proper innodb_log_file_size
    ffmpeg 常用命令
    opencv 知识点笔记
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5123935.html
Copyright © 2011-2022 走看看