<%@page import="java.io.File"%>

<%@page import="java.io.FileWriter"%>

<%

  String path = "D:/Program Files/apache-tomcat-7.0.55/wtpwebapps/Ad/res/res/role";//遍历路径

  String splitStr = "D:\\\\Program Files\\\\apache-tomcat-7.0.55\\\\wtpwebapps\\\\Ad\\\\res\\\\res\\\\";//剔除路径

   StringBuffer buffer=new StringBuffer();

  buffer.append("{\r\n");

   buffer.append("\t\"res\""+":[\r\n");

   func(path,splitStr,buffer);

  buffer.delete(buffer.length()-3,buffer.length()-1);

   buffer.append("\t]\r\n"); buffer.append("}");

  out.print(buffer.toString());

%>

<%!

   void func(String path,String splitStr,StringBuffer buffer)

   {

    File file = new File(path);

    File[] tempList = file.listFiles();

     for(int i=0;i<tempList.length;i++)

     {

       if(tempList[i].isFile())

       {

         String[] subStr = String.valueOf(tempList[i]).split(splitStr);

        String str_1 = subStr[subStr.length-1].replaceAll("\\\\","/");

         try {

           buffer.append("\t\t\""+str_1+"\""+",\r\n");

        } catch (Exception e)

        {}

         }

      else if(tempList[i].isDirectory())// 如果改文件是一个文件夹,递归遍历改目录下文件

       {

        func(String.valueOf(tempList[i]),splitStr,buffer);

      }

  }

 }

%>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-09-06
猜你喜欢
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案