Ho rimesso mano al codice
codice:
import java.util.*;
import java.io.*;
class Settings {
private String Name;
private Integer Port;
public Settings() {
this("", 0);
}
public Settings(String Name, int port) {
this.Name = Name;
Port = new Integer(port);
}
public Settings (String cfgFileName) throws Exception {
this();
this.load(new FileInputStream(cfgFileName));
}
public void save(FileOutputStream outStream) {
try {
Properties prop = new Properties();
prop.setProperty("Name", Name);
prop.setProperty("Port", Port.toString());
}
catch (Exception e) {
System.out.println("Error on saving:"+e.toString());
e.printStackTrace();
}
}
public void load(FileInputStream inStream) {
try {
Properties prop = new Properties();
prop.load(inStream);
Name=prop.getProperty("Name");
Port=new Integer(prop.getProperty("Port"));
}
catch (Exception e) {
System.out.println("Error on loading :"+e.toString());
}
}
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name=Name;
}
public Integer getPort() {
return Port;
}
public void setPort(Integer Port) {
this.Port=Port;
}
}
codice:
public class TestSettings {
public static void main(String[] args) throws Exception {
Settings mySettings = new Settings("settings.cfg");
System.out.print(mySettings.getName());
}
}
Edit: ho editato, facendo l'incolla mi ero perso mezza classe Settings