Configs.java
1.06 KB
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 cn.org.hentai.jtt1078.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* Created by matrixy on 2017/8/14.
*/
public final class Configs
{
static Properties properties = new Properties();
public static void init(String configFilePath)
{
try
{
File file = new File((configFilePath.startsWith("/") ? "." : "") + configFilePath);
if (file.exists()) properties.load(new FileInputStream(file));
else properties.load(Configs.class.getResourceAsStream(configFilePath));
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static String get(String key)
{
Object val = properties.get(key);
if (null == val) return null;
else return String.valueOf(val).trim();
}
public static int getInt(String key, int defaultVal)
{
String val = get(key);
if (null == val) return defaultVal;
else return Integer.parseInt(val);
}
}