码迷,mamicode.com
首页 > 其他好文 > 详细

UploadUtils

时间:2016-10-18 22:39:26      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

public class UploadUtils {  /**   * 截取真实文件名   *   * @param fileName   * @return   */  

public static String subFileName(String fileName) {   

// 查找最后一个 \出现位置  

 int index = fileName.lastIndexOf("\\");  

 if (index == -1) {    return fileName;   }   

return fileName.substring(index + 1);  }

 // 获得随机UUID文件名  

public static String generateRandomFileName(String fileName) {   // 获得扩展名   String ext = fileName.substring(fileName.lastIndexOf("."));   return UUID.randomUUID().toString() + ext;  }

 // 获得hashcode生成二级目录  public static String generateRandomDir(String uuidFileName) {   int hashCode = uuidFileName.hashCode();   // 一级目录   int d1 = hashCode & 0xf;   // 二级目录   int d2 = (hashCode >> 4) & 0xf;   return "/" + d1 + "/" + d2;  } }

UploadUtils

标签:

原文地址:http://www.cnblogs.com/jasonlee880709/p/5974868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!