读取属性文件

@ 在项目路径下创建一个text:

   jco.client.ashost=host
   jco.client.client=client

   保存另存为user.properties

@

public static void main(String[] args) throws SQLException, IOException {
        String currpath = new File("").getAbsolutePath()                          
                +"\\user.properties";  //获取属性文件的绝对路径
        System.out.println(currpath);
        Properties prop = new Properties();  
        InputStream in;
        try {
            in = new FileInputStream(new File(currpath));//读属性文件
            if(in != null){  
                prop.load(in);  
                String ashost = prop.getProperty("jco.client.ashost");  
                String clientnr = prop.getProperty("jco.client.client");  
                System.out.println(ashost);
                System.out.println(clientnr);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

 

posted @ 2013-06-17 10:53  爱笑的狐狸  阅读(203)  评论(0编辑  收藏  举报