CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

有人能给我解释一下这个程序吗?

楼主kim_thinker()2006-12-02 09:34:11 在 Java / J2SE / 基础类 提问

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

相关问题

关键词

得分解答快速导航

  • 帖主:kim_thinker

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo