zhaowenyu
2025-10-28 b0da63410a7aaf64b11183c95b3da38013a6457b
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
package com.ard.route.util;
 
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
 
/**
 * 工具类
 */
public class ToolUtils {
 
    /**
     * 生成KMZ文件名称规则
     */
    public static String buildKmzFileName() {
        // 获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        return "测试KMZ文件" + "_" + now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"));
    }
 
    /**
     * 根据路径截取文件名
     */
    public static String getFileNameWithoutExtension(String filePath) {
        if (filePath == null || filePath.trim().isEmpty()) {
            return "";
        }
 
        // 规范化路径,处理正斜杠和反斜杠
        String normalizedPath = filePath.replace('\\', '/');
 
        // 获取文件名(含扩展名)
        String fileNameWithExt = normalizedPath.substring(normalizedPath.lastIndexOf('/') + 1);
 
        // 去除扩展名
        int lastDotIndex = fileNameWithExt.lastIndexOf('.');
        if (lastDotIndex > 0) {
            return fileNameWithExt.substring(0, lastDotIndex);
        }
 
        return fileNameWithExt;
    }
 
}