java的subString和lastIndexOf的简单应用,
分享于 点击 5867 次 点评:79
java的subString和lastIndexOf的简单应用,
开代码吧
List<Map<String,Object>> lstMaps = dailyOfficeDao.AppSelectFileById(map);
resultMap.put("id", lstMaps.get(0).get("id").toString());//把查询出来的id放到resultMap中
resultMap.put("file_type", lstMaps.get(0).get("fil_typ").toString());//文件类型
resultMap.put("fil_nam", lstMaps.get(0).get("fil_nam").toString());//文件原名
resultMap.put("fil_url", lstMaps.get(0).get("fil_url").toString());//存放路径
String filePath = lstMaps.get(0).get("fil_url").toString();//存放路径 如 D:\file\0f01c32d-7e2f-4551-a484-a3ec94b11415.jpg
int index = filePath.lastIndexOf("\\");//最后出现 \ 的下标
String name = filePath.substring(index+1);// 截取的话 是包含 \ 下标的 所有 下标要 +1
resultMap.put("newName",name);//把文件 经过uuid改造过的新的名字 放到resultMap中
String path = PropertiesUtil.getProperty("file.prefix") + name; //加上 访问路径的前缀 如 http://127.0.0.1:8080/file/
resultMap.put("path",path);//再放到resultMap 中
完了
相关文章
- 暂无相关文章
用户点评