RelativePathUtil.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.fuzamei.utils;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. /**
  5. *
  6. * @author ylx
  7. * @describe: 用于生成相对路径的一个工具类
  8. */
  9. public class RelativePathUtil {
  10. private RelativePathUtil() {
  11. throw new AssertionError("不能实例化 RelativePathUtil");
  12. }
  13. /**
  14. *
  15. * @Title: formatPath
  16. * @Description: TODO(产生一个pattern格式的相对路径,用于拼接使用)
  17. * @param @param date
  18. * @param @param pattern
  19. * @param @return 设定文件
  20. * @return String 返回类型
  21. * @author ylx
  22. * @date 2017年12月29日 下午5:14:36
  23. * @throws
  24. */
  25. public static final String formatPath(final Date date, String pattern){
  26. if (date != null) {
  27. SimpleDateFormat dateformatter = new SimpleDateFormat(pattern);
  28. String dateString = dateformatter.format(date);
  29. return dateString;
  30. }
  31. throw new RuntimeException("date should not be null");
  32. }
  33. /**
  34. *
  35. * @Title: formatPath
  36. * @Description: TODO(相对路径格式为 /yyyy/MM/dd/HH/mm/ss/ )
  37. * @param @return 设定文件
  38. * @return String 返回类型
  39. * @author ylx
  40. * @date 2017年12月29日 下午5:19:26
  41. * @throws
  42. */
  43. public static final String formatPath(){
  44. return formatPath(new Date(),"/yyyy/MM/dd/HH/mm/ss/");
  45. }
  46. /**
  47. *
  48. * @Title: formatPath
  49. * @Description: TODO(根据需求传入默认路径的前缀和后缀)
  50. * @param @param prefix
  51. * @param @param sufix
  52. * @param @return 设定文件
  53. * @return String 返回类型
  54. * @author ylx
  55. * @date 2017年12月29日 下午5:38:51
  56. * @throws
  57. */
  58. public static final String formatPath(String prefix,String sufix){
  59. return prefix+formatPath()+sufix;
  60. }
  61. }