logo 西林@生存 - 骑猪闯天下!
JSP读写Properties文件
2006-12-11 17:09:00 By:xling
<%
Properties users = new Properties();
InputStream in = application.getResourceAsStream("/WEB-INF/users.properties");
users.load(in);
//InputStream in = application.getResourceAsStream("/WEB-INF/users.xml");
//users.loadFromXML(in);
out.println(users.getProperty("userName"));
users.setProperty("userName","xling");
users.setProperty(users.getProperty("userName") + ".sex","male");
users.setProperty(users.getProperty("userName") + ".password","哈哈!~");
FileOutputStream fout = new FileOutputStream(application.getRealPath("/") + "/WEB-INF/users.properties",false);
FileOutputStream fout2 = new FileOutputStream(application.getRealPath("/") + "/WEB-INF/users.xml",false);
users.store(fout,"users.properties");
users.storeToXML(fout2,"aaaaaaaaa");
%>

生成的XML文件格式:

<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
   <comment>aaaaaaaaa</comment>
   <entry key="xling.sex">male</entry>
   <entry key="xling.password">哈哈!~</entry>
   <entry key="userName">xling</entry>
</properties>

生成的properties文件格式:

#users.properties
#Mon Dec 11 17:12:27 CST 2006
xling.sex=male
xling.password=\u54C8\u54C8\uFF01\uFF5E
userName=xling

可用来允当INI文件噢!
转我的贴,写你的名,是一种可耻的行为!请不要让我BS你!
阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:

    密码:
    主页:
    标题:
    页面数据正在载入...
<<  < 2007 - 12 >  >>
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Placard
1,長江後浪推前浪,前浪死在沙灘上!
2,有了钱的男人,才是真正的男人...
3,不要以为把你的小JJ埋进土里,你就rape了整个地球;不要以为把你的小JJ朝向天空,你就rape了整个宇宙!
Logon System
Search
Info about this blog
Others
myDream
bxna 京ICP备05002321号