?? configmanager.java
字號:
/*
* ConfigManager.java
*
* Copyright (C) 2004 Jay Scott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (gpl.txt); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package config;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
/**
* This class reads from a properties file that contains user defined options
* such as what port to bind the WAP Server to. It reads these properties into
* public available variables so that other classes can access the information.
*
*@author Jay Scott
*@created July 21, 2004
*@version 0.4
*/
public class ConfigManager {
/**
* Gets the logPath attribute of the ConfigManager object
*
* @return The logPath value
*/
public String getLogPath() {
String LogPath = "logs";
try {
Properties config = new Properties();
config.load(new FileInputStream("WAPServer.properties"));
LogPath = (config.getProperty("LogPath"));
} catch (IOException e) {
return LogPath;
}
return LogPath;
}
/**
* Gets the portNumber attribute of the ConfigManager object
*
* @return The portNumber value
*/
public int getPortNumber() {
int PortNumber = 8765;
try {
Properties config = new Properties();
config.load(new FileInputStream("WAPServer.properties"));
PortNumber = Integer.parseInt(config.getProperty("Port").trim());
} catch (IOException e) {
return PortNumber;
}
return PortNumber;
}
/**
* Gets the passcode attribute of the ConfigManager object
*
* @return The passcode value
*/
public String getPasscode() {
String Passcode = "12345";
try {
Properties config = new Properties();
config.load(new FileInputStream("WAPServer.properties"));
Passcode = config.getProperty("Passcode");
} catch (IOException e) {
return Passcode;
}
return Passcode;
}
/**
* Gets the passcode attribute of the ConfigManager object
*
* @return The passcode value
*/
public int getSplash() {
int splash = 1;
try {
Properties config = new Properties();
config.load(new FileInputStream("WAPServer.properties"));
splash = Integer.parseInt(config.getProperty("Splash").trim());
} catch (IOException e) {
return splash;
}
return splash;
}
/**
* writes the passed in data to the configuration file
*
* @param portNo
* Holds the new port number
* @param logLocation
* Holds the new log path location
* @param passcode
* Holds the new login passcode
* @return Returns a boolean true if successful
*/
public boolean writeConfig(String portNo, String logLocation,
String passcode) {
try {
Properties config = new Properties();
config.put("Port", portNo);
config.put("LogPath", logLocation);
config.put("Passcode", passcode);
config.store(new FileOutputStream("WAPServer.properties"), null);
} catch (IOException e) {
return false;
}
return true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -