张洋洋
2025-01-09 6cb2134a53422f471f4f9b77c34d67e1fb4d31db
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
package com.se.simu.utils;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
/**
 *
 */
public class FileUtil {
    public static String getShpPath(String dirPath) {
        File root = new File(dirPath);
        List<String> filePath=new ArrayList<>();
        traverse(root,filePath);
        for (String path:filePath
             ) {
            if (path.endsWith(".shp")){
                return path;
            }
        }
        return null;
    }
 
    public static void traverse(File dir,List<String> filePath) {
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    traverse(file, filePath);
                } else {
                    filePath.add(file.getAbsolutePath());
                }
            }
        }
    }
 
}