目录结果:
工具类:
package com.inforstack.plugman; import java.io.File; public class Plugin { //插件的相对目录 private static String basePath = "src/android/demo"; //插件的绝对目录 private static String path = "D:\\work\\cordova\\plugin\\demo\\src\\android\\demo"; public static void main(String[] args) { getFile(path); } private static void getFile(String path) { // 获取路径所在的文件列表 File dirFile = new File(path); // 获取文件列表 File[] array = dirFile.listFiles(); for (File file : array) { if (file.isFile()) { toXML(file.getName(),file.getPath()); } else if (file.isDirectory()) { getFile(file.getPath()); } } } private static void toXML(String fileName,String filePath) { if (fileName.indexOf(".java") != -1 || fileName.indexOf(".xml") != -1 || fileName.indexOf(".png") != -1) { String newFilePath = filePath.replace(path,""); String newDirPath = newFilePath.replace("\\" + fileName,""); newDirPath = newDirPath.substring(1,newDirPath.length()); String xml = String.format("<source-file src=\"%s%s\" target-dir=\"%s\" />",basePath,newFilePath,newDirPath); xml = xml.replace("\\","/"); System.out.println(xml); } else if (fileName.indexOf(".jar") != -1) { String newFilePath = filePath.replace(path,""); String xml = String.format("<lib-file src=\"%s%s\"/>",newFilePath); xml = xml.replace("\\","/"); System.out.println(xml); } } }