yubo
2026-04-08 d90db860b7ea15a6d6c58a3e77b649966f3ab6bf
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
package cc.mrbird.febs.server.hr.util;
 
import java.io.*;
import java.util.Properties;
 
public class GetFilePlace {
 
    /**
     * 读取文件,获取excel保存的根目录
     * 
     * @return excel保存的根目录
     */
    public String getFilePath() {
        String dir = System.getProperty("user.dir"); // 获得tomcat所在的工作路径
        String realDir = dir + File.separator+ "febs-server" + File.separator
                + "febs-server-hr" + File.separator+ "src" + File.separator + "main" + File.separator + "resources"
                + File.separator + "application.properties";
        // 获取到存储了文件存储位置的filedir.properties 文件路径 --->java Project的文件路径
        return realDir;
    }
 
    /**
     * 获取filePath路径【properities文件】中key对应的值,
     * 
     * @param filePath
     *            properities文件路径【包含properities文件】
     * @param key
     *            要查找的key值
     * @return key对应的value
     */
    public String GetValueByKey(String filePath, String key) {
        Properties pps = new Properties();
        try {
            InputStream in = new BufferedInputStream(new FileInputStream(filePath));
            pps.load(in);
            String value = pps.getProperty(key);
            in.close();
            return value;
 
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
 
    /**
     * 查询properities文件中可以对应的存储地点
     * 
     * @param key
     *            查询主键
     * @return key对应的存储地址
     */
    public String getFileDirFromProperties(String key) {
        return GetValueByKey(getFilePath(), key);
    }
}