创建路径

来源:互联网 发布:嵌入式软件开发实例 编辑:程序博客网 时间:2024/06/06 02:56

import java.io.File;

/**
  * 构建路径
  * @param stopath
  * @return
  */
 public static String getPathPath(String stopath){

     // path : stopath/planpdf/ym/dd/
     DateFormat ym = new SimpleDateFormat("yyyyMM");
     DateFormat dd = new SimpleDateFormat("dd");
     Date date = new Date();
     StringBuffer path = new StringBuffer(stopath);
     path.append("planpdf");
     File dir1 = new File(path.toString());
     if (!dir1.exists()) //判断路径是否存在
        dir1.mkdirs();
     path.append(File.separator).append(ym.format(date));
     File dir2 = new File(path.toString());
     if (!dir2.exists())
       dir2.mkdirs();
     path.append(File.separator).append(dd.format(date)).append(File.separator);
     File dir3 = new File(path.toString());
     if (!dir3.exists())
      dir3.mkdirs();
     return path.toString();
 }

原创粉丝点击