Klasse Main:
private static Config InitConfiguration(String filename)
{
Config configTemp = new Config();
try
{
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
XMLDecoder xmlDecoder = new XMLDecoder(bis);
configTemp = (Config) xmlDecoder.readObject();
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
return configTemp;
}
{
Config configTemp = new Config();
try
{
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
XMLDecoder xmlDecoder = new XMLDecoder(bis);
configTemp = (Config) xmlDecoder.readObject();
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
return configTemp;
}
Klasse Config:
public class Config implements Serializable
{
private static final long serialVersionUID = 1L;
private String serverName;
private int serverPort;
private String user;
private String password;
public String getServerName()
{
return serverName;
}
public void setServerName(String serverName)
{
this.serverName = serverName;
}
public int getServerPort()
{
return serverPort;
}
public void setServerPort(int serverPort)
{
this.serverPort = serverPort;
}
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
Die Config.xml-Datei:
<?xml version="1.0" encoding="UTF-8" ?>
<java version="1.8.0_20" class="SSHServerRestartPackage.SSHServerRestart">
<object class="SSHServerRestartPackage.Config">
<void property="serverName">
<string>202.202.202.202</string>
</void>
<void property="serverPort">
<int>22</int>
</void>
<void property="user">
<string>root</string>
</void>
<void property="password">
<string>IhrPasswort</string>
</void>
</object>
</java>
{
private static final long serialVersionUID = 1L;
private String serverName;
private int serverPort;
private String user;
private String password;
public String getServerName()
{
return serverName;
}
public void setServerName(String serverName)
{
this.serverName = serverName;
}
public int getServerPort()
{
return serverPort;
}
public void setServerPort(int serverPort)
{
this.serverPort = serverPort;
}
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
Die Config.xml-Datei:
<?xml version="1.0" encoding="UTF-8" ?>
<java version="1.8.0_20" class="SSHServerRestartPackage.SSHServerRestart">
<object class="SSHServerRestartPackage.Config">
<void property="serverName">
<string>202.202.202.202</string>
</void>
<void property="serverPort">
<int>22</int>
</void>
<void property="user">
<string>root</string>
</void>
<void property="password">
<string>IhrPasswort</string>
</void>
</object>
</java>
Keine Kommentare:
Kommentar veröffentlichen