日期:2014-05-18 浏览次数:20681 次
/** * Description :获得图标路径列表 * @param Object * @return Object */ public Object getPicture(Object o){ ShortcutData shortcut = (ShortcutData)o; ShortcutData temp = new ShortcutData(); List data = new ArrayList(); File pathName = new File("E:/workspace/ics/WebRoot/images/img"); String[] fileNames = pathName.list(); String str = " "; for(int i=0;i<fileNames.length;i++) { File f=new File(pathName.getPath(),fileNames[i]); try { if(i==0){ str = f.getCanonicalPath(); }else{ str = str + "," + f.getCanonicalPath(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(str != null || !str.equals("")){ for(int i=0;i<str.split(",").length-1;i++){ temp = new ShortcutData(); Log.log(str.split(",")[i].replace("E:\\workspace\\ics\\WebRoot", "..")); temp.setType(str.split(",")[i].replace("E:\\workspace\\ics\\WebRoot", "..")); data.add(temp); } } shortcut.setType_list(data); return shortcut; }
------解决方案--------------------
request.getContextPath()+"/Webwebroot"
------解决方案--------------------
遍历文件夹
<%@ page contentType="text/html; charset=gb2312" %> <%@ page import="java.io.*" %> <% String url1="C:/aaa"; File f=(new File(url1)); if(f.isDirectory()){ File [] fe = f.listFiles(); go_on: for (int i = 0;i<fe.length;i++){ if (fe[i].isDirectory()){ File [] fe1 = fe[i].listFiles(); for (int j = 0;j<fe1.length;j++){ if (fe1[j].isDirectory()) continue go_on; out.println(fe1[j].toString()); } } else out.println(fe[i].toString()); } }