有人能给我解释一下这个程序吗?
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
class abc {
private Properties settings;
abc() throws IOException {
try {
settings = new Properties();
settings.load(new FileInputStream("c:\\count.txt"));
} catch (FileNotFoundException e) {
settings.store(new FileOutputStream("c:\\count.txt"),("this program is used:"));
}
}
private String computerName;
private String ip;
private String dbName;
private String user;
private String pw;
public String getPropertyValue(String propertyName) {
return settings.getProperty(propertyName);
}
public void setPropertyValue(String propertyName, String propertyValue)
throws FileNotFoundException, IOException {
settings.put(propertyName, propertyValue);
settings.store(new FileOutputStream("c:\\count.txt"),
("this program is used:"));
}
public void setComputerName(String computerName)
throws FileNotFoundException, IOException {
setPropertyValue("computerName", computerName);
this.computerName = computerName;
}
public String getComputerName() {
return computerName;
}
void setIp(String ip) throws FileNotFoundException, IOException {
setPropertyValue("ip", ip);
this.ip = ip;
}
String getIp() {
return ip;
}
void setDbName(String dbName) throws FileNotFoundException, IOException {
setPropertyValue("dbname", dbName);
this.dbName = dbName;
}
String getDbName() {
return dbName;
}
void setUser(String user) throws FileNotFoundException, IOException {
setPropertyValue("user", user);
this.user = user;
}
String getUser() {
return user;
}
void setPw(String pw) throws FileNotFoundException, IOException {
setPropertyValue("pw", pw);
this.pw = pw;
}
String getPw() {
return pw;
}
public static void main(String[] args) throws FileNotFoundException,
IOException {
abc xyz = new abc();
xyz.setComputerName("Admin");
System.out.println(xyz.getComputerName());
xyz.setIp("192.168.0.1");
System.out.println(xyz.getIp());
xyz.setDbName("mydbname_firstdb");
System.out.println(xyz.getDbName());
xyz.setUser("myusername");
System.out.println(xyz.getUser());
xyz.setPw("mypassword");
System.out.println(xyz.getPw());
}
}
问题点数:10、回复次数:5Top
1 楼mathsfan(mathsfan)回复于 2006-12-02 09:42:12 得分 0
不大懂,帮你顶一下Top
2 楼benq998(问题没解决,坚决不结贴.解决了还不结贴,极度鄙视.)回复于 2006-12-02 10:05:23 得分 0
看样子相似在配置一个数据库的连接参数,不过这样做好像有点刻意的去面向对象了,没有必要。Top
3 楼haisenmai(我应该做得到)回复于 2006-12-02 10:07:35 得分 0
大概就是 通过 Properties赋值再取值Top
4 楼kim_thinker()回复于 2006-12-02 10:53:23 得分 0
没有人能够详细的解释一下吗?
Top
5 楼zzffrr(zzffrr)回复于 2006-12-02 11:16:09 得分 0
读去配置文件!看来你的基础比较差,好好补一下基础吧!Top




