📄 configutil.java
字号:
package org.lazybug.util;
import java.util.Properties;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: www.lazybug.com Copyright (c) 2003</p>
* <p>Company: </p>
* @author 刘学
* @version 1.0
*/
public class ConfigUtil
{
public static String WEB_PATH = "";
public static String APP_CONFIGPATH = "";
public static String APP_PATH = "";
private static long lastModify = 0;
private static Properties Config = new Properties();
public static void setPath(String path)
{
int i;
if( ( i=path.lastIndexOf("bin") ) != -1 )
{
APP_PATH = path.substring(0, i);
}
else
{
APP_PATH = path;
}
APP_CONFIGPATH = APP_PATH + "config/config.properties";
loadConfig();
}
private static void loadConfig()
{
try
{
File fobj = new File(APP_CONFIGPATH);
if (fobj.exists())
{
FileInputStream fis = new FileInputStream(fobj);
Config.load(fis);
fis.close();
lastModify = fobj.lastModified();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static int getInteger(String id)
{
String result;
if (id == null)
{
return 0;
}
if (Config.size() == 0)
{
loadConfig();
}
else
{
File file = new File(APP_CONFIGPATH);
if(file.lastModified() > lastModify)
{
lastModify = file.lastModified();
loadConfig();
}
}
result = Config.getProperty(id,id);
if( result.equals(id))
{
result = "-1";
}
return Integer.parseInt(result);
}
public static void setString(String id, String value)
{
if (id == null || value == null || id.equals("") || value.equals(""))
{
return;
}
if (Config.size() == 0)
{
loadConfig();
}
Config.setProperty(id, value);
}
/*
* Read the information from Config table
*/
public static String getString(String id)
{
String result;
if (id == null)
{
return "";
}
if (Config.size() == 0)
{
loadConfig();
}
else
{
File file = new File(APP_CONFIGPATH);
if(file.lastModified() > lastModify)
{
lastModify = file.lastModified();
loadConfig();
}
}
result = Config.getProperty(id, "");
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -