/**
* 根据http://127.0.0.1:8080/cms/ReadAddress/1479805098158.jpg 读取图片
* @param imgUrl
* @return
* @throws Exception
*/
public String ReadAddress(String imgUrl) throws Exception {
String path = Global.getDirPath();
System.out.println(path);
String image = imgUrl.substring(imgUrl.lastIndexOf("/")+1);
System.out.println(image);
File root = new File(path);
if(true == root.exists()){
showAllFiles(root, image);
}else{
System.out.println("Invalid Path");
}
return image;
}
//获取地址
final static void showAllFiles(File dir, String image) throws Exception{
File[] fs = dir.listFiles();
for(int i=0; i<fs.length; i++){
if(fs[i].isDirectory()){
try{
showAllFiles(fs[i], image);
}catch(Exception e){}
}else if(fs[i].getName().contains(image)){
System.out.println(fs[i].getAbsolutePath());
}else{
}
}
}
最后获取: