zoukankan      html  css  js  c++  java
  • JSP工程中的读配置文件方法

    代码
    package com.vmm.config;

    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;



    public class Config {
    private static String CONFIG_FILE_PATH = "/config.properties";
    private static Config inst;
    private String ip;
    private int port;
    private Config(){
    init();
    }
    public static Config getInstance(){
    if(inst==null){
    inst
    =new Config();
    }
    return inst;
    }
    private void init(){
    System.out.println(
    "init//////////");
    InputStream in
    =getClass().getResourceAsStream(CONFIG_FILE_PATH);
    Properties pro
    = new Properties();
    try {
    pro.load(in);
    in.close();
    }
    catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    ip
    =pro.getProperty("ip");
    port
    =Integer.parseInt(pro.getProperty("port"));

    }
    public String getIP(){
    return ip;
    }
    public int getPort(){
    return port;
    }
    }

    config.properties放在src根目录下

  • 相关阅读:
    「CodeForces
    「POJ
    「CodeForces
    「CodeForces
    【CodeForces 717C】Potions Homework
    【CodeForces 730H】Car Repair Shop
    【CodeForces 730H】Delete Them
    【Gym 100947I】What a Mess
    j
    PDE工具箱的简单使用
  • 原文地址:https://www.cnblogs.com/yangyh/p/1911721.html
Copyright © 2011-2022 走看看