动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息

本月文章推荐
.Sun StorEdge Instant ImageT.
.Session Facade 的规则和模式.
.用Filter实现IP过滤.
.使用JDOM操作XML系列文章三 平面.
.用纯JAVA语言编程读取MAC地址的实.
.JAVA mail应用 - 用JAVA SWING写.
.面向方面编程的Annotation简介.
.Spring 中文开发手册.
.字符终端的管理.
.RMI原理及实现.
.Java连接数据库谈.
.Java与XML(三)WEB上的读写应用.
.Java的网络知识.
.细细讲述Java技术开发的规则之开.
.continue 语句.
.循序渐进学习Junit.
.数组在Java编程中的应用.
.使用struts,ibaits和JSTL开发简便.
.揭开J2EE集群Cluster的神秘面纱.
.Servlet和JavaServerPages的集成.

使用Properties从文件获取属性

发表日期:2008-1-5 |


import Java.util.*;
import java.io.*;

/**
 * refer to http://www-900.ibm.com/developerWorks/cn/java/j-tiger02254/index_eng.sHtml  </br>
 * or http://www-900.ibm.com/developerWorks/cn/java/j-tiger02254/index.shtml
 */
public class LoadProperties
{
 public static void main(String[] args) throws Exception {
  Properties prop = new Properties();

  //load properties from configuration file
  System.out.println("From properties file:");
  FileInputStream fis = new FileInputStream("sample.properties");
  prop.load(fis);
     prop.list(System.out);
  System.out.println("\nThe foo property: " + prop.getProperty("foo"));
  
  //load properties from XML property file(Tiger new method)
  System.out.println("From xml file:");
  fis =new FileInputStream("sampleprops.xml");
  /**
   *<pre>The XML document must have the following DOCTYPE declaration:
   *<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
   *the dtd file :
   *<?xml version="1.0" encoding="UTF-8"?>
   *<!-- DTD for properties -->
   *<!ELEMENT properties ( comment?, entry* ) >
   *<!ATTLIST properties version CDATA #FIXED "1.0">
   *<!ELEMENT comment (#PCDATA) >
   *<!ELEMENT entry (#PCDATA) >
   *<!ATTLIST entry key CDATA #REQUIRED>
         *</pre>
   */
  prop.loadFromXML(fis);  
  prop.list(System.out);
  System.out.println("\nThe foo property: " + prop.getProperty("foo"));
  
  //生成xml文件
  System.out.println("prodUCe a xml file");
  prop = new Properties();
  prop.setProperty("one-two", "buckle my shoe");
  prop.setProperty("three-four", "shut the door");
     prop.setProperty("five-six", "pick up sticks");
  prop.setProperty("seven-eight", "lay them straight");
     prop.setProperty("nine-ten", "a big, fat hen");
  FileOutputStream fos = new FileOutputStream("rhyme.xml");
  /*
   *default encoding is UTF-8,
   * if you need specify encoding,
   * use storeToXML(OutputStream os,String comment,String encoding) instead
   */
  prop.storeToXML(fos, "Rhyme");//prop.storeToXML(fos, "Rhyme","GBK");
     fos.close();//The specified stream remains open after storeToXML() returns,so must close obviously
  /**
   *生成的xml如下(DTD如上所述):
   *<?xml version="1.0" encoding="UTF-8"?>
   *<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
   *<properties>
   *<comment>Rhyme</comment>
   *<entry key="seven-eight">lay them straight</entry>
   *<entry key="five-six">pick up sticks</entry>
   *<entry key="nine-ten">a big, fat hen</entry>
   *<entry key="three-four">shut the door</entry>
   *<entry key="one-two">buckle my shoe</entry>
   *</properties>
   */
 }
}


上一篇:JUnit -- A good thing to unit test 人气:542
下一篇:关于分页问题(ZT) 人气:898
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-10-12 team论坛 v2.0.4 bulid 080916 A
2008-10-12 Roclog v3.1.6
2008-10-12 SupeV v1.0.1 简体中文 GBK
2008-10-12 NetCMS v1.6.0.1010 正式版
2008-10-12 PHP考试系统PPFrame v1.2.7
2008-10-12 LPAS个人相册 v1.6.3
2008-10-12 快问仿百度知道系统 动态-静态-互
2008-10-12 方卡广告防点击系统 V1.0 GB2312
2008-10-12 泡菜内容管理系统[PCMS] v1.0 Bu
2008-10-11 联系人分组工具 v1.1 中文破解版
2008-10-11 FaceMelter变脸 v2.0 汉化破解版
2008-10-11 PathTracker道路跟踪仪 v1.2 破解
2008-10-11 Rooms手机聊天室 v0.6.7 破解版
2008-10-11 RemoteDesktop远程桌面 v1.0 破解
2008-10-11 ProRemote远程调音台 v1.0.1 破解
2008-10-11 PicShare照片共享 v1.0.0 破解版
2008-10-11 Photogene照片编辑器 v1.5 汉化破
2008-10-11 WriteRoom共享文档 v1.0 破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号