⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverinfo.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.server;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class ServerInfo {
	public final static String	DEFAULT_HOST		= "192.168.11.21";
	public final static int		DEFAULT_PORT		= 80;
	public final static boolean	DEFAULT_USE_HTTPS	= false;
	public final static String	DEFAULT_PATH		= "/SPS";
	public final static String	DATA_FILE_NAME		= "./serverInfo.properties";
	public final static String	HTTP_STR			= "http://";
	public final static String	HTTPS_STR			= "https://";
	public final static String	SERVLET_DIR_STR		= "/servlet/";
	
	public final static String	KEY_HOST			= "host";
	public final static String	KEY_PORT			= "port";
	public final static String	KEY_USEHTTPS		= "useHttps";
	public final static String	KEY_PATH			= "path";
	
	private String		host;
	private int		port;
	private boolean	useHttps;
	private String		path;
	private String		fileName;
	
	public ServerInfo() {
		this.host = DEFAULT_HOST;
		this.port = DEFAULT_PORT;
		this.useHttps = DEFAULT_USE_HTTPS;
		this.path = DEFAULT_PATH;
		this.fileName = DATA_FILE_NAME;
	}
	
	public String getHost() {
		return host;
	}
	
	public void setHost(String host) {
		this.host = host;
	}
	
	public int getPort() {
		return port;
	}
	
	public void setPort(int port) {
		this.port = port;
	}
	
	public boolean isUseHttps() {
		return useHttps;
	}
	
	public void setUseHttps(boolean useHttps) {
		this.useHttps = useHttps;
	}
	
	public String getPath() {
		return path;
	}
	
	public void setPath(String path) {
		this.path = path;
	}
	
	public String getDocBase() {
		return (useHttps ? HTTPS_STR : HTTP_STR) + host + ":" + Integer.toString(port) + path + SERVLET_DIR_STR;
	}
	
	public void readFromFile() throws FileNotFoundException, IOException {
		FileInputStream	fi = new FileInputStream(fileName);
		Properties		prop = new Properties();
		prop.load(fi);
		
		setHost(prop.getProperty(KEY_HOST, DEFAULT_HOST));
		setPort(Integer.parseInt(prop.getProperty(KEY_PORT, String.valueOf(DEFAULT_PORT))));
		setUseHttps(new Boolean(prop.getProperty(KEY_USEHTTPS, String.valueOf(DEFAULT_USE_HTTPS))).booleanValue());
		setPath(prop.getProperty(KEY_PATH, DEFAULT_PATH));
	}
	
	public void writeToFile() throws IOException {
		FileOutputStream	fo = new FileOutputStream(fileName);
        Properties	prop = new Properties();
    
        if (host != null) {
        	prop.setProperty(KEY_HOST, host);
        } else {
        	prop.setProperty(KEY_HOST, "");
        }
        prop.setProperty(KEY_PORT, String.valueOf(port));
        prop.setProperty(KEY_USEHTTPS, String.valueOf(useHttps));
        if (path != null) {
        	prop.setProperty(KEY_PATH, path);
        } else {
        	prop.setProperty(KEY_PATH, "");
        }
        prop.store(fo, null);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -