admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
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
package com.yeshi.fanli.util;
 
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
 
import javax.servlet.http.HttpServletRequest;
 
public class PropertyUtil {
    public static Properties getPropertys(String fileName) {
 
        ClassLoader classLoader = PropertyUtil.class.getClass().getClassLoader();
        Properties pe = new Properties();
        try {
            pe.load(classLoader.getResourceAsStream(fileName));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pe;
    }
 
    // 获取属性
    public static Properties getPropertys(HttpServletRequest request, String fileName) {
        try {
            if (request.getSession().getServletContext().getAttribute(StringUtil.getBase64String(fileName)) != null)
                return (Properties) request.getSession().getServletContext()
                        .getAttribute(StringUtil.getBase64String(fileName));
            Properties pe = getPropertys(fileName);
            request.getSession().getServletContext().setAttribute(StringUtil.getBase64String(fileName), pe);
            return pe;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}