首页 > 其他 > 详细

UploadUtils

时间:2016-10-18 22:36:39      阅读:546      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!