I made this for a friend but he didn't like it so ill release here. What this does is it loads values from a XML file, its basically the same thing as a "cfg file" but its faster and more efficient. I also documented this out of boredom. Make a new class file named ServerConf and paste this inside:
Code:
import java.util.Properties;
import java.io.IOException;
import java.io.FileInputStream;
/**
* This class loads different values for various
* variables/methods for the server from a XML file.
*
* @arthur Samuraiblood2
*/
public class ServerConf {
Properties props;
String dir = "./xml/";
String file = "settings.xml";
/**
* Uses the defualt file and directory to load
* the values. The default directory is <code>./xml/</code> and
* the default file name is <code>settings.xml</code>.
*/
public ServerConf() {
props = new Properties();
try {
FileInputStream in = new FileInputStream(dir + file);
props.loadFromXML(in);
} catch(IOException e) {
e.printStackTrace();
}
}
/**
* Sets the files directory and the files name then reads any
* and all values from the specified file.
*
* @param dir The location of the file.
* @param file The name of the file.
*/
public ServerConf(String dir, String file) {
this.dir = dir;
this.file = file;
props = new Properties();
try {
FileInputStream in = new FileInputStream(dir + file);
if(file.endsWith("xml")) {
props.loadFromXML(in);
} else {
props.load(in);
}
} catch(IOException e) {
e.printStackTrace();
}
}
/**
* Gets the name of the servers owner.
*
* @return The servers owners name.
*/
public String getOwner() {
String owner = props.getProperty("Owner");
return owner;
}
/**
* Gets the name of the server.
*
* @return The server name.
*/
public String getServer() {
String server = props.getProperty("Server");
return server;
}
/**
* Gets the startup message for the server.
*
* @return The message that will be printed.
*/
public String getStartMsg() {
String msg = props.getProperty("Msg");
return msg;
}
/**
* Gets the servers port.
*
* @return The servers port.
*/
public int getServPort() {
int port = Integer.parseInt(
props.getProperty("Port"));
return port;
}
}
Now, make a folder called xml and make a file named settings.xml, inside that file paste this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="KEYTYPE">VALUE</entry>
</properties>
Replace KEYTYPE with the keytype obviously and replace VALUE with a value.