java.util.Properties 类里有些方法,专门处理配置文件,你可以看看。

解决方案 »

  1.   

    除了使用Properties外,还可以通过File和BufferedReader将ini文件读取出来,读出后还能够做进一步的处理
      

  2.   

    String recordsPerPage="0";
    properties = new Properties();
    InputStream is = null;
    try{
    is = getClass().getResourceAsStream("/../pbcenter.properties");
    properties.load(is);
    } catch(Exception e) {
    System.out.println("Can't read properties file");
    } finally {
    try{
    if(is != null)
    is.close();
    } catch(IOException e) {
    //ignore
    }
    }
                               recordsPerPage=properties.getProperty("SYS.RECORDS_PER_PAGE");
      

  3.   

    看看Properties类,应该能给你帮助的。楼上的代码应该可用。
      

  4.   

    try{
          ResourceBundle rb = ResourceBundle.getBundle("SmsSC");
          this.Sms_IP=rb.getString("Sms_IP");
          this.Sms_Port=rb.getString("Sms_Port");
        }catch(Exception e){
            System.err.println("读取系统配置信息失败了!请确定文件MailSC.properties是否存在!错误:" + e.getMessage());
        }
      

  5.   

    config文件
    DBdriver=com.microsoft.jdbc.sqlserver.SQLServerDriver
    DBConfig=jdbc:microsoft:sqlserver://gwserver3:1433;databasename=train,train,'',
    MAXConnection=50读取private void readConfig(String cfgfile) { Properties pps = new Properties() ; try {
    BufferedReader in = new BufferedReader(new FileReader(cfgfile));
    String s = null ;
    while ((s = in.readLine()) != null ) {
    int iLoc = s.indexOf('=') ;
    if (iLoc >= 0) {
    System.out.println(s);
    pps.put(s.substring(0,iLoc).toLowerCase().trim(),s.substring(iLoc+1).trim());
    }
    }
    in.close();
    }
    catch (FileNotFoundException e) {
    System.out.println("basefun.readconfig:"+e);
    }
    catch (IOException e){
    System.out.println("basefun.readconfig:"+e);
    } String strDriver = (String) pps.get("dbdriver") ;
    String strDbcfg = (String) pps.get("dbconfig") ;
    String strMaxcon = (String) pps.get("maxconnection") ;
    int iMaxcon = Integer.parseInt(strMaxcon) ; String strOpFile = (String) pps.get("opfile") ;
    String strChnFile = (String) pps.get("chndicfile") ; Pool = new ConnectionPool(strDriver,strDbcfg,iMaxcon) ;
    // Pool.run() ;// initChnDic(strChnFile) ;    //文件形式存放的中文字典表
    // initChnDic() ; //数据库形式存放的中文字典表// Oplist = new OPList(Pool); //数据库形式存放的数据库操作步骤表-------lijian  先禁掉,以后再用2002-06-04
    // Oplist = new OPList(strOpFile); //文件形式存放的数据库操作步骤表
    initTableDic() ; }