package com.highdatas.srs.util; import com.alibaba.fastjson.JSONObject; import java.io.File; import java.io.UnsupportedEncodingException; import java.util.ArrayList; /** * @author kimi * @description * @date 2020-01-16 11:13 */ public class FileUtils { public static ArrayList getChildrenFiles(String rootPath) throws UnsupportedEncodingException { File rootFile = new File(rootPath); File parentFile = rootFile.getParentFile(); File[] files = rootFile.listFiles(); ArrayList fileArray = new ArrayList<>(); if (files == null) { return fileArray; } for (File one : files) { JSONObject object = new JSONObject(); if (one.isDirectory()) { object.fluentPut("file", false); } else { object.fluentPut("file", true); } object.fluentPut("path", one.getAbsolutePath()); object.fluentPut("parent", rootPath); object.fluentPut("grandPa", parentFile.getAbsolutePath()); object.fluentPut("name", one.getName()); fileArray.add(object); } return fileArray; } public static String strJoin(String... objects){ ContentBuilder builder = new ContentBuilder(Constant.EMPTY); for (String object : objects) { builder.append(object); } return builder.toString(); } public static String createFile(String basePath,String project, String detail) { String path = strJoin(basePath, "/", project,"/" ,detail); File dir = new File(path); if (!dir.exists()) { dir.mkdirs(); } return path; } public static String getFilePath(String basePath,String project, String detail) { String path = strJoin(basePath, project, detail); File dir = new File(path); if (!dir.exists()) { dir.mkdirs(); } return path; } }