String comments = new String();
try
{
File f = new File(config.getFile_url()+config.getConfigFileName()+".properties");
f.createNewFile();
PrintWriter pw = new PrintWriter(new FileWriter(f));
p.setProperty("FILE_URL", config.getFile_url());
p.setProperty("NETWORK_NAME", config.getNetwork_name());
p.setProperty("IP_ADDRESS", config.getIp_address());
p.setProperty("MASK",config.getMask());
p.setProperty("GATEWAY",config.getGateway());
p.setProperty("GWMETRIC",config.getGwmetric());
p.setProperty("DNS_FIRST",config.getDns_first());
p.setProperty("DNS_REMARK",config.getDns_remark());
p.setProperty("WEB_COUNT", config.getWeb_count());
p.setProperty("WEB_URL",config.getWeb_url());
p.setProperty("FILE_NAME",config.getConfigFileName());
p.store(pw, comments);
}
catch(IOException e)
{
System.out.println("+----->写配置文件异常!");
e.printStackTrace();
}
}
public static SystemVars ReadConfigFile(String fileName)
{
String fileURL = "D:\IP_CONFIG"+fileName+".properties";
SystemVars config = new SystemVars();
Properties p = new Properties();
try
{
FileReader fr = new FileReader(fileURL);
p.load(fr);
config.setConfigFileName(p.getProperty("FILE_NAME"));
config.setFile_url(p.getProperty("FILE_URL"));
config.setNetwork_name(p.getProperty("NETWORK_NAME"));
config.setIp_address(p.getProperty("IP_ADDRESS"));
config.setMask(p.getProperty("MASK"));
config.setGateway(p.getProperty("GATEWAY"));
config.setGwmetric(p.getProperty("GWMETRIC"));
config.setDns_first(p.getProperty("DNS_FIRST"));
config.setDns_remark(p.getProperty("DNS_REMARK"));
config.setNetwork_name(p.getProperty("NETWORK_NAME"));
config.setWeb_count(p.getProperty("WEB_COUNT"));
config.setWeb_url(p.getProperty("WEB_URL"));
//FileReader必须和文件断开
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
return config;
}
public static void createPFile(SystemVars config)
{
//生成新的目录
ConfigFile.mkdir(config.getFile_url());
String [] str = new String[7];
//生成P处理命令
str[0]="pushd interface ip ";
str[1]="set address name="+config.getNetwork_name()+" source=static addr="+config.getIp_address()+" mask="+config.getMask();
str[2]="set address name="+config.getNetwork_name()+" gateway="+config.getGateway()+" gwmetric="+config.getGwmetric();
str[3]="set dns name="+config.getNetwork_name()+" source=static addr="+config.getDns_first();
str[4]="add dns name="+config.getNetwork_name()+" addr="+config.getDns_remark();
str[5]="set wins name="+config.getNetwork_name()+" source=static addr=none ";
str[6]="popd ";
//生成P文件
ConfigFile.createFile(config.getFile_url()+config.getConfigFileName()+".txt" , str );
}
public static void mkdir(String path)
{
String mkdirName = path;
try
{
File dirFile = new File(mkdirName);
boolean bFile = dirFile.exists();
if(!bFile)//如果文件目录不存在
{
bFile = dirFile.mkdir();
if(!bFile)//如果文件目录创建失败
{
//添加文件目录创建失败弹出信息代码
System.exit(1);
}
}
} catch(Exception err)
{
System.err.println("+-------->文件夹创建发生异常");
System.out.println("+-------->"+err.g