kimi
2020-11-27 75c32d6d697a550400d0b4eec95b8570d83b726f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.highdatas.srs.util;
 
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
 
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<JSONObject> getChildrenFiles(String rootPath) throws UnsupportedEncodingException {
        File rootFile = new File(rootPath);
        File parentFile = rootFile.getParentFile();
        File[] files = rootFile.listFiles();
        ArrayList<JSONObject> 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;
        if (StringUtils.isEmpty(detail)) {
            path = strJoin(basePath, "/", project);
        }
        else {
            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;
    }
}