站点图标 起风网

计算上传文件的存放路径

计算上传文件的存放路径缩略图
     //计算文件的存放目录
   //filename:处理后的唯一的文件名
   //storeDirectory:文件要存放的根目录:getServletContext().getRealPath("/files");
private String genericPath(String filename, String storeDirectory) { int hashCode = filename.hashCode(); int dir1 = hashCode&0xf; int dir2 = (hashCode&0xf0)>>4; String dir = "/"+dir1+"/"+dir2; File file = new File(storeDirectory,dir); if(!file.exists()){ file.mkdirs(); } return dir; }

文件上传至服务器中,服务器分成多级文件夹来存放,一种情况是使用当前日期来区分文件夹,一种就是可以用hashcode来区分,就是上面的代码。

文章转载于:https://www.cnblogs.com/lm970585581/p/8655382.html

原著是一个有趣的人,若有侵权,请通知删除

退出移动版