JSP学习笔记(十五):读取properties配置文件的节点内容

在src目录建立p.properties配置文件,内容为:

str1=111111111
str2
=222222222

 

操作函数:

    public String getContent() {
        String content 
= "";

        
try {
            Properties properties 
= new Properties();
            InputStream is 
= getClass().getClassLoader().getResourceAsStream("p.properties");//加载p.properties文件内容
            properties.load(is);//将文件内容装载到properties对象
            is.close();
            content 
= properties.getProperty("str1");//获取str1节点值
        } catch (FileNotFoundException ex) {
            
        } 
catch (IOException ex) {
            
        }

        
return content;
    }
posted @ 2008-08-13 14:18  魔豆  阅读(2238)  评论(0)    收藏  举报