String s = ""; File dir = new File(path); if (dir != null && dir.isDirectory()) { String absolutePath = dir.getAbsolutePath();
absolutePath = absolutePath.replaceAll("\\\\", "\\\\\\\\");//对'\'的处理,在JSP参数传递时'\'和空格会出现错误 absolutePath = absolutePath.replaceAll(" ", "@"); //对空格的处理 ,这时用'@'替代 s += "new Array(" + index + ",'<a href=fileList.jsp?path=" + absolutePath + "\\\\ target=mainFrame>" + dir.getName() + "</a>'," + hasNexetBrother + "), "; hasNexetBrother = false; index++; File[] dirs = dir.listFiles(); java.util.List list = new java.util.ArrayList(); for (int i = 0; i < dirs.length; i++) { if (dirs[i].isDirectory()) {//去除文件.得到文件夹列表
list.add(dirs[i]);
} } for (int i = 0; i < list.size(); i++) { if (i != list.size() - 1) hasNexetBrother = true; String dirpath = ((File) list.get(i)).getAbsolutePath(); s += showFileTree(dirpath);//对子文件夹递归处理